[bluesky] add 'following' extractor (#4438)
This commit is contained in:
@@ -149,6 +149,17 @@ class BlueskyListExtractor(BlueskyExtractor):
|
|||||||
return self.api.get_list_feed(self.user, self.list)
|
return self.api.get_list_feed(self.user, self.list)
|
||||||
|
|
||||||
|
|
||||||
|
class BlueskyFollowingExtractor(BlueskyExtractor):
|
||||||
|
subcategory = "following"
|
||||||
|
pattern = USER_PATTERN + r"/follows"
|
||||||
|
example = "https://bsky.app/profile/HANDLE/follows"
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
for user in self.api.get_follows(self.user):
|
||||||
|
url = "https://bsky.app/profile/" + user["did"]
|
||||||
|
yield Message.Queue, url, user
|
||||||
|
|
||||||
|
|
||||||
class BlueskyPostExtractor(BlueskyExtractor):
|
class BlueskyPostExtractor(BlueskyExtractor):
|
||||||
subcategory = "post"
|
subcategory = "post"
|
||||||
pattern = USER_PATTERN + r"/post/([^/?#]+)"
|
pattern = USER_PATTERN + r"/post/([^/?#]+)"
|
||||||
@@ -206,6 +217,14 @@ class BlueskyAPI():
|
|||||||
}
|
}
|
||||||
return self._pagination(endpoint, params)
|
return self._pagination(endpoint, params)
|
||||||
|
|
||||||
|
def get_follows(self, actor):
|
||||||
|
endpoint = "app.bsky.graph.getFollows"
|
||||||
|
params = {
|
||||||
|
"actor": self._did_from_actor(actor),
|
||||||
|
"limit": "100",
|
||||||
|
}
|
||||||
|
return self._pagination(endpoint, params, "follows")
|
||||||
|
|
||||||
def get_list_feed(self, actor, list):
|
def get_list_feed(self, actor, list):
|
||||||
endpoint = "app.bsky.feed.getListFeed"
|
endpoint = "app.bsky.feed.getListFeed"
|
||||||
params = {
|
params = {
|
||||||
@@ -293,10 +312,10 @@ class BlueskyAPI():
|
|||||||
"API request failed (%s %s)",
|
"API request failed (%s %s)",
|
||||||
response.status_code, response.reason)
|
response.status_code, response.reason)
|
||||||
|
|
||||||
def _pagination(self, endpoint, params):
|
def _pagination(self, endpoint, params, key="feed"):
|
||||||
while True:
|
while True:
|
||||||
data = self._call(endpoint, params)
|
data = self._call(endpoint, params)
|
||||||
yield from data["feed"]
|
yield from data[key]
|
||||||
|
|
||||||
cursor = data.get("cursor")
|
cursor = data.get("cursor")
|
||||||
if not cursor:
|
if not cursor:
|
||||||
|
|||||||
Reference in New Issue
Block a user