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
1 changed files with 19 additions and 9 deletions

28
sync.py
View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from pprint import pprint from pprint import pprint
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
import concurrent.futures
import json import json
import os import os
import requests import requests
@ -60,6 +61,17 @@ def set_card_style_id(card_id:int, style_id:int):
return False 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(): def pull_all():
card_ids = get_card_ids() card_ids = get_card_ids()
for card_id in card_ids: for card_id in card_ids:
@ -139,13 +151,11 @@ def push_style():
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
if len(sys.argv) < 4: if len(sys.argv) < 4:
print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'push', 'push_style' or 'pull'\n") print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'list', 'push', 'push_style' or 'pull'\n")
elif sys.argv[1].strip().lower() == "pull": else:
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3]) AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
pull_all() action = sys.argv[1].strip().lower()
elif sys.argv[1].strip().lower() == "push": if action == "list": list_collections()
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3]) if action == "pull": pull_all()
push_all() if action == "push": push_all()
elif sys.argv[1].strip().lower() == "push_style": if action == "push_style": push_style()
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_style()