aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpatchodon.py47
1 files changed, 37 insertions, 10 deletions
diff --git a/patchodon.py b/patchodon.py
index 18d5753..734d7e5 100755
--- a/patchodon.py
+++ b/patchodon.py
@@ -30,16 +30,21 @@ def api_token(args):
raise ("API token not specified")
-def do_post_status(args, body, parent=None, optional=None):
- if len(body) > STATUS_LENGTH_LIMIT:
- raise ("required status body too long")
-
+def auth_headers(args):
if not args.instance_url:
raise ("mastodon instance not specified")
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 + (
"\n" + optional[0 : (STATUS_LENGTH_LIMIT - len(body) - 1)]
if optional
@@ -129,13 +134,35 @@ def do_post(args):
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):
- # search & resolve the status ID on the instance (if configured)
- # get context, all replies from the same author as the original status ID
- # cycle the same for all hashes
+ st_id, st_acct_id, st_content = find_head_post(args)
+ # parse out the hash and subhashes
+ # get context, all replies from the same author as the original status ID, subhashes must match
+ # repeat for all subhashes
# verify the full hash
- # pass to git-am OR throw to a directory
- pass
+ # pass as one blob to git-am OR throw to a directory
def main():