From d7bdfaf8f6340281109c7e44fe8b108ee6f73b42 Mon Sep 17 00:00:00 2001 From: VG Date: Tue, 28 Nov 2017 21:33:11 +0100 Subject: first test at having a cli for dumping anime information from anidb in yaml format --- cli.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 cli.py (limited to 'cli.py') diff --git a/cli.py b/cli.py new file mode 100755 index 0000000..9bc6c39 --- /dev/null +++ b/cli.py @@ -0,0 +1,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')) -- cgit v1.2.3