aboutsummaryrefslogtreecommitdiffstats
path: root/cli.py
blob: 9bc6c397c09dd29726b90091601930d6f71388ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3

import sys
import collections

import anidb
import yaml

def setup_yaml():
    """ https://stackoverflow.com/a/8661021 """
    represent_dict_order = lambda self, data: self.represent_mapping(
            'tag:yaml.org,2002:map', data.items())
    yaml.add_representer(collections.OrderedDict, represent_dict_order)
    yaml.SafeDumper.add_representer(collections.OrderedDict, represent_dict_order)

setup_yaml()

adb = anidb.AniDB('anishow', client_ver=1)
results = adb.search(sys.argv[1:])

print('results: ', results)
result = results[-1]
print('choosing result -1:', result)

print('result.type:', result.type)
#print('result.startdate:', result.startdate)

for result in results:
    print('dump yaml:')
    print('='*60)
    print(yaml.safe_dump(collections.OrderedDict(
        title=result.title,
        type=result.type,
        description=result.description,
        episodecount=result.episodecount,
        #startdate=result.startdate,
        #enddate=result.enddate,
        anidb_aid=result.aid,
    ), encoding='utf8', allow_unicode=True,
    default_flow_style=False).decode('utf8'))