From c7be23ca04daa1f3ee3439529485e73a46a5b271 Mon Sep 17 00:00:00 2001 From: kiliczsh Date: Sat, 22 Apr 2023 22:48:52 +0300 Subject: [PATCH] Implement new endpoints --- gokyuzu/BlueskyEndpoints.py | 6 ++++++ gokyuzu/BlueskySession.py | 7 +++++++ gokyuzu/__init__.py | 35 +++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- setup.py | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/gokyuzu/BlueskyEndpoints.py b/gokyuzu/BlueskyEndpoints.py index b7af4b6..73c8191 100644 --- a/gokyuzu/BlueskyEndpoints.py +++ b/gokyuzu/BlueskyEndpoints.py @@ -74,6 +74,12 @@ def getAuthorFeed(self): def getPostThread(self): return self.get_url("/xrpc/app.bsky.feed.getPostThread") + def getLikes(self): + return self.get_url("/xrpc/app.bsky.feed.getLikes") + + def getRepostedBy(self): + return self.get_url("/xrpc/app.bsky.feed.getRepostedBy") + # app.bsky.graph def getFollowers(self): return self.get_url("/xrpc/app.bsky.graph.getFollowers") diff --git a/gokyuzu/BlueskySession.py b/gokyuzu/BlueskySession.py index b02b22e..c6beef9 100644 --- a/gokyuzu/BlueskySession.py +++ b/gokyuzu/BlueskySession.py @@ -64,6 +64,13 @@ def post(self, url, data=None, json=None, **kwargs): response = requests.post(url, headers=headers, data=data, json=json, **kwargs) return response + def post(self, url, headers=None, data=None, json=None, **kwargs): + if headers is None: + headers = {} + headers['Authorization'] = f'Bearer {self.getAccessToken()}' + response = requests.post(url, headers=headers, data=data, json=json, **kwargs) + return response + def postJson(self, url, json, **kwargs): headers = { 'Authorization': f'Bearer {self.getAccessToken()}', 'Content-Type': 'application/json' } response = requests.post(url, headers=headers, json=json, **kwargs) diff --git a/gokyuzu/__init__.py b/gokyuzu/__init__.py index a6a6b49..720be25 100644 --- a/gokyuzu/__init__.py +++ b/gokyuzu/__init__.py @@ -81,6 +81,16 @@ def getPostThread(self, post_id, limit=10, cursor=""): response = self.SESSION.get(request_url) return response + def getLikes(self, post_id, limit=10, cursor=""): + request_url = self.ENDPOINTS.getLikes() + "?uri={}&limit={}&cursor={}".format(post_id, limit, cursor) + response = self.SESSION.get(request_url) + return response + + def getRepostedBy(self, post_id, limit=10, cursor=""): + request_url = self.ENDPOINTS.getRepostedBy() + "?uri={}&limit={}&cursor={}".format(post_id, limit, cursor) + response = self.SESSION.get(request_url) + return response + # app.bsky.graph def getFollowers(self, handle=None, user_did=None, limit=10, cursor=""): if handle: @@ -197,3 +207,28 @@ def health(self): request_url = self.ENDPOINTS.health() response = self.SESSION.get(request_url) return response + + def uploadImage(self, image_path, content_type="image/jpeg"): + request_url = self.ENDPOINTS.uploadBlob() + headers = {"Content-Type": content_type} + with open(image_path, 'rb') as f: + data = f.read() + response = self.SESSION.post(request_url, data=data, headers=headers) + return response + + def searchTypeAhead(self, query="", limit=10): + typeahead_url = "https://bsky.social/xrpc/app.bsky.actor.searchActorsTypeahead" + request_url = "{}?term={}&limit={}".format(typeahead_url, query, limit) + response = self.SESSION.get(request_url) + return response + + def search(self, query_type="posts", query=""): + request_url = "https://search.bsky.social/search/{}?q={}".format(query_type, query) + response = self.SESSION.get(request_url) + return response + + def search_profiles(self, query): + return self.search(query_type="profiles", query=query) + + def search_posts(self, query): + return self.search(query_type="posts", query=query) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1a3adfc..5bf685e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [tool.poetry] name = "gokyuzu" -version = "1.0.0" +version = "1.0.1" description = "bsky.social client library" authors = ["Muhammed Kılıç "] license = "MIT" diff --git a/setup.py b/setup.py index 263f2c4..8a7e7e1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='gokyuzu', - version='1.0.0', + version='1.0.1', description='bsky.social client library', long_description=open('README.md', 'r', encoding='utf-8').read(), long_description_content_type='text/markdown',