Ver Fonte

share all prunplanner plans in an account

raylu há 2 semanas atrás
pai
commit
a1604fca67
2 ficheiros alterados com 31 adições e 2 exclusões
  1. 1 2
      prunplanner/copy_empire.py
  2. 30 0
      prunplanner/share.py

+ 1 - 2
prunplanner/copy_empire.py

@@ -5,9 +5,8 @@ import httpx
 
 def main():
 	from_jwt, empire_uuid, to_jwt = sys.argv[1:]
-	from_headers = {'Authorization': 'Bearer ' + from_jwt}
 
-	with httpx.Client(headers=from_headers) as from_client:
+	with httpx.Client(headers={'Authorization': 'Bearer ' + from_jwt}) as from_client:
 		empire: typing.Sequence[EmpirePlan] = from_client.get('https://api.prunplanner.org/baseplanner/empire/' + empire_uuid).raise_for_status().json()
 		shared: typing.Mapping[str, str] = {s['plan_uuid']: s['shared_uuid']
 				for s in from_client.get('https://api.prunplanner.org/shared/list').raise_for_status().json()}

+ 30 - 0
prunplanner/share.py

@@ -0,0 +1,30 @@
+import sys
+import typing
+
+import httpx
+
+def main():
+	jwt,= sys.argv[1:]
+
+	client = httpx.Client(headers={'Authorization': 'Bearer ' + jwt})
+	plans: typing.Sequence[Plan] = client.get('https://api.prunplanner.org/baseplanner/').raise_for_status().json()
+	shared: typing.Mapping[str, str] = {s['plan_uuid']: s['shared_uuid']
+			for s in client.get('https://api.prunplanner.org/shared/list').raise_for_status().json()}
+	for plan in plans:
+		if plan['uuid'] not in shared:
+			print('sharing', plan['uuid'], plan['name'])
+			client.put('https://api.prunplanner.org/shared/baseplanner/' + plan['uuid']).raise_for_status()
+	# refresh shared UUIDs
+	shared: typing.Mapping[str, str] = {s['plan_uuid']: s['shared_uuid']
+			for s in client.get('https://api.prunplanner.org/shared/list').raise_for_status().json()}
+
+	for plan in plans:
+		shared_uuid = shared[plan['uuid']]
+		print(plan['name'], 'https://prunplanner.org/shared/' + shared_uuid)
+
+class Plan(typing.TypedDict):
+	uuid: str
+	name: str
+
+if __name__ == '__main__':
+	main()