summaryrefslogtreecommitdiff
path: root/hello-fusepy.py
diff options
context:
space:
mode:
authoruvok2025-01-19 18:23:48 +0100
committeruvok2025-01-19 18:23:48 +0100
commitbc0f3a819096d11af030803868f0e64b3917999d (patch)
tree7e6c40704e8a0e1bb32ba8b99fd96f596a3c783a /hello-fusepy.py
parent9ba368c93eb1c73da60be590bfbfe533a90c84cb (diff)
Begin Mastodon implementation
Diffstat (limited to 'hello-fusepy.py')
-rw-r--r--hello-fusepy.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/hello-fusepy.py b/hello-fusepy.py
index 13a0968..ff9fd42 100644
--- a/hello-fusepy.py
+++ b/hello-fusepy.py
@@ -15,7 +15,7 @@ from fuse import (
fuse_exit,
fuse_get_context,
)
-
+import urllib.parse
class APIChoice(enum.Enum):
ACTIVITYPUB = "ActivityPub"
@@ -23,6 +23,7 @@ class APIChoice(enum.Enum):
api_url_ap_template = "https://{server}/users/{user}/outbox?page=true"
+api_url_m_lookup_template = "https://{server}/api/v1/accounts/lookup"
class Status(object):
@@ -62,12 +63,32 @@ class ActivityPubStatusProvider(StatusProvider):
if s["type"] == "Create"
]
+class MastodonStatusProvider(StatusProvider):
+ def __init__(self, server: str, user: str):
+ self.server = server
+ self.user = user
+ self.userid = 0
+
+ def load_statuses(self) -> list[Status]:
+ url = api_url_m_lookup_template.format(server=self.server)
+ url += "?" + urllib.parse.urlencode({"acct": self.user})
+ res = requests.get(url)
+ if res.status_code == 404:
+ return self._fallback_not_found()
+ res.raise_for_status()
+ user = res.json()
+ self.userid = user["id"]
+ return self._fallback_not_found()
+
class HelloWorld(Operations, LoggingMixIn):
def __init__(self, api: APIChoice, server: str, user: str):
self.statuses: list[Status] = []
self.fd = 0
self.api = api
- self.status_provider = ActivityPubStatusProvider(server, user)
+ if api == APIChoice.MASTODON:
+ self.status_provider = MastodonStatusProvider(server, user)
+ else:
+ self.status_provider = ActivityPubStatusProvider(server, user)
def getattr(self, path, fh=None):
(uid, gid, _) = fuse_get_context()
@@ -143,9 +164,6 @@ def parse_arguments():
else:
parser.error("Must choose either ActivityPub or Mastodon API")
- if args.api_choice != APIChoice.ACTIVITYPUB:
- raise NotImplementedError("Not supported yet")
-
return args
def main(args):