start the retrieval work
This commit is contained in:
		
							parent
							
								
									dcf143d556
								
							
						
					
					
						commit
						a7309aa1c1
					
				
							
								
								
									
										47
									
								
								patchodon.py
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								patchodon.py
									
									
									
									
									
								
							|  | @ -30,16 +30,21 @@ def api_token(args): | ||||||
|     raise ("API token not specified") |     raise ("API token not specified") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def do_post_status(args, body, parent=None, optional=None): | def auth_headers(args): | ||||||
|     if len(body) > STATUS_LENGTH_LIMIT: |  | ||||||
|         raise ("required status body too long") |  | ||||||
| 
 |  | ||||||
|     if not args.instance_url: |     if not args.instance_url: | ||||||
|         raise ("mastodon instance not specified") |         raise ("mastodon instance not specified") | ||||||
| 
 | 
 | ||||||
|     token = api_token(args) |     token = api_token(args) | ||||||
| 
 | 
 | ||||||
|     headers = {"Authorization": f"Bearer {token}"} |     return {"Authorization": f"Bearer {token}"} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def do_post_status(args, body, parent=None, optional=None): | ||||||
|  |     if len(body) > STATUS_LENGTH_LIMIT: | ||||||
|  |         raise ("required status body too long") | ||||||
|  | 
 | ||||||
|  |     headers = auth_headers(args) | ||||||
|  | 
 | ||||||
|     st = body + ( |     st = body + ( | ||||||
|         "\n" + optional[0 : (STATUS_LENGTH_LIMIT - len(body) - 1)] |         "\n" + optional[0 : (STATUS_LENGTH_LIMIT - len(body) - 1)] | ||||||
|         if optional |         if optional | ||||||
|  | @ -129,13 +134,35 @@ def do_post(args): | ||||||
|     print(url) |     print(url) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def find_head_post(args): | ||||||
|  |     headers = auth_headers(args) | ||||||
|  |     r = requests.get( | ||||||
|  |         args.instance_id + "/api/v2/search", | ||||||
|  |         params={"resolve": "true", "limit": "10", "q": args.patch_url}, | ||||||
|  |     ) | ||||||
|  |     print(r.__dict__) | ||||||
|  |     if r.status_code != 200: | ||||||
|  |         raise ("status URL search failed!") | ||||||
|  | 
 | ||||||
|  |     sts = filter(lambda x: x["url"] == args.patch_url, r.json()["statuses"]) | ||||||
|  | 
 | ||||||
|  |     if len(sts) < 1: | ||||||
|  |         raise ("status URL not found") | ||||||
|  | 
 | ||||||
|  |     if len(sts) > 1: | ||||||
|  |         raise ("ambiguous status URL?") | ||||||
|  | 
 | ||||||
|  |     st = sts[0] | ||||||
|  |     return (st["id"], st["account"]["id"], st["content"]) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def do_get(args): | def do_get(args): | ||||||
|     # search & resolve the status ID on the instance (if configured) |     st_id, st_acct_id, st_content = find_head_post(args) | ||||||
|     # get context, all replies from the same author as the original status ID |     # parse out the hash and subhashes | ||||||
|     # cycle the same for all hashes |     # get context, all replies from the same author as the original status ID, subhashes must match | ||||||
|  |     # repeat for all subhashes | ||||||
|     # verify the full hash |     # verify the full hash | ||||||
|     # pass to git-am OR throw to a directory |     # pass as one blob to git-am OR throw to a directory | ||||||
|     pass |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue