Skip to content

Commit 74e98de

Browse files
committed
add command get-subscriptions
1 parent ee40530 commit 74e98de

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

inoreader/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,41 @@ def filter_articles(rules_file):
253253
apply_action([article], client, 'tag', action['tags'])
254254

255255

256+
@main.command("get-subscriptions")
257+
@click.option("-o", "--outfile", help="Filename to save results")
258+
@click.option("-f", "--folder", help='Folder which subscriptions belong to')
259+
@click.option("--out-format",
260+
type=click.Choice(["json", "csv"]), default="csv",
261+
help="Format of output, default: csv")
262+
def get_subscriptions(outfile, folder, out_format):
263+
"""Get your subscriptions"""
264+
client = get_client()
265+
results = []
266+
for sub in client.get_subscription_list():
267+
sub_categories = set([category['label'] for category in sub.categories])
268+
if folder and folder not in sub_categories:
269+
continue
270+
271+
results.append({
272+
'id': sub.id,
273+
'title': sub.title,
274+
'url': sub.url,
275+
'folders': ';'.join(sub_categories),
276+
})
277+
278+
fout = open(outfile, 'w') if outfile else sys.stdout
279+
if out_format == 'csv':
280+
headers = ['id', 'title', 'url', 'folders']
281+
writer = csv.DictWriter(fout, headers, quoting=csv.QUOTE_ALL, delimiter="\t")
282+
writer.writeheader()
283+
for item in results:
284+
writer.writerow(item)
285+
elif out_format == 'json':
286+
json.dump(results, fout, ensure_ascii=False, indent=4)
287+
288+
if outfile:
289+
fout.close()
290+
291+
256292
if __name__ == '__main__':
257293
main()

0 commit comments

Comments
 (0)