add 'list' to sync.py

This commit is contained in:
Peder Bergebakken Sundt 2019-10-14 19:34:45 +02:00
parent 82fa84a4cb
commit 96d1c66384

28
sync.py
View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
from pprint import pprint
from requests.auth import HTTPBasicAuth
import concurrent.futures
import json
import os
import requests
@ -60,6 +61,17 @@ def set_card_style_id(card_id:int, style_id:int):
return False
def list_collections():
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as e:
resp = requests.get("https://www.pvv.ntnu.no/~andreasd/cards/command.php?cmd=get_all_cards", auth=AUTH)
print("== All collections: ==\n")
for i in resp.json():
print("id: ", i["id"])
print("name: ", i["name"])
print("cards: ", i["cards"])
print("card styles: ", sorted(set(map(int, e.map(get_card_style_id,i["cards"])))))
print()
def pull_all():
card_ids = get_card_ids()
for card_id in card_ids:
@ -139,13 +151,11 @@ def push_style():
if __name__ == "__main__":
import sys
if len(sys.argv) < 4:
print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'push', 'push_style' or 'pull'\n")
elif sys.argv[1].strip().lower() == "pull":
print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'list', 'push', 'push_style' or 'pull'\n")
else:
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
pull_all()
elif sys.argv[1].strip().lower() == "push":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_all()
elif sys.argv[1].strip().lower() == "push_style":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_style()
action = sys.argv[1].strip().lower()
if action == "list": list_collections()
if action == "pull": pull_all()
if action == "push": push_all()
if action == "push_style": push_style()