mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-06-16 21:54:43 +02:00
Refactor
This commit is contained in:
@@ -24,31 +24,24 @@ class UserBuffer(BaseBuffer):
|
||||
api_method = self.kwargs.get("api_method")
|
||||
if not api_method: return 0
|
||||
|
||||
count = self.session.settings["general"].get("max_posts_per_call", 50)
|
||||
count = self.get_max_items()
|
||||
actor = (
|
||||
self.kwargs.get("actor")
|
||||
or self.kwargs.get("did")
|
||||
or self.kwargs.get("handle")
|
||||
or self.kwargs.get("id")
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
# We call the method in session. API methods return {"items": [...], "cursor": ...}
|
||||
if api_method in ("get_followers", "get_follows"):
|
||||
res = getattr(self.session, api_method)(actor=actor, limit=count)
|
||||
else:
|
||||
res = getattr(self.session, api_method)(limit=count)
|
||||
items = res.get("items", [])
|
||||
self.next_cursor = res.get("cursor")
|
||||
|
||||
# Clear existing items for these lists to start fresh?
|
||||
# Or append? Standard lists in TWBlue usually append.
|
||||
# But followers/blocks are often full-sync or large jumps.
|
||||
# For now, append like timelines.
|
||||
|
||||
return self.process_items(items, play_sound)
|
||||
except Exception:
|
||||
log.exception(f"Error fetching user list for {self.name}")
|
||||
except Exception as e:
|
||||
log.error("Error fetching user list for %s: %s", self.name, e)
|
||||
return 0
|
||||
|
||||
def get_more_items(self):
|
||||
@@ -56,7 +49,7 @@ class UserBuffer(BaseBuffer):
|
||||
if not api_method or not self.next_cursor:
|
||||
return
|
||||
|
||||
count = self.session.settings["general"].get("max_posts_per_call", 50)
|
||||
count = self.get_max_items()
|
||||
actor = (
|
||||
self.kwargs.get("actor")
|
||||
or self.kwargs.get("did")
|
||||
@@ -73,8 +66,8 @@ class UserBuffer(BaseBuffer):
|
||||
added = self.process_items(items, play_sound=False)
|
||||
if added:
|
||||
output.speak(_(u"%s items retrieved") % (str(added)), True)
|
||||
except Exception:
|
||||
log.exception(f"Error fetching more user list items for {self.name}")
|
||||
except Exception as e:
|
||||
log.error("Error fetching more user list items for %s: %s", self.name, e)
|
||||
|
||||
class FollowersBuffer(UserBuffer):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -102,8 +95,8 @@ class FollowersBuffer(UserBuffer):
|
||||
timelines.remove(key)
|
||||
self.session.settings["other_buffers"]["followers_timelines"] = timelines
|
||||
self.session.settings.write()
|
||||
except Exception:
|
||||
log.exception("Error updating Bluesky followers timelines settings")
|
||||
except Exception as e:
|
||||
log.error("Error updating Bluesky followers timelines settings: %s", e)
|
||||
return True
|
||||
|
||||
class FollowingBuffer(UserBuffer):
|
||||
@@ -132,8 +125,8 @@ class FollowingBuffer(UserBuffer):
|
||||
timelines.remove(key)
|
||||
self.session.settings["other_buffers"]["following_timelines"] = timelines
|
||||
self.session.settings.write()
|
||||
except Exception:
|
||||
log.exception("Error updating Bluesky following timelines settings")
|
||||
except Exception as e:
|
||||
log.error("Error updating Bluesky following timelines settings: %s", e)
|
||||
return True
|
||||
|
||||
class BlocksBuffer(UserBuffer):
|
||||
@@ -152,20 +145,20 @@ class PostUserListBuffer(UserBuffer):
|
||||
def start_stream(self, mandatory=False, play_sound=True):
|
||||
if not self.api_method or not self.post_uri:
|
||||
return 0
|
||||
count = self.session.settings["general"].get("max_posts_per_call", 50)
|
||||
count = self.get_max_items()
|
||||
try:
|
||||
res = getattr(self.session, self.api_method)(self.post_uri, limit=count)
|
||||
items = res.get("items", [])
|
||||
self.next_cursor = res.get("cursor")
|
||||
return self.process_items(items, play_sound)
|
||||
except Exception:
|
||||
log.exception("Error fetching post user list for %s", self.name)
|
||||
except Exception as e:
|
||||
log.error("Error fetching post user list for %s: %s", self.name, e)
|
||||
return 0
|
||||
|
||||
def get_more_items(self):
|
||||
if not self.api_method or not self.post_uri or not self.next_cursor:
|
||||
return
|
||||
count = self.session.settings["general"].get("max_posts_per_call", 50)
|
||||
count = self.get_max_items()
|
||||
try:
|
||||
res = getattr(self.session, self.api_method)(self.post_uri, limit=count, cursor=self.next_cursor)
|
||||
items = res.get("items", [])
|
||||
@@ -173,8 +166,8 @@ class PostUserListBuffer(UserBuffer):
|
||||
added = self.process_items(items, play_sound=False)
|
||||
if added:
|
||||
output.speak(_(u"%s items retrieved") % (str(added)), True)
|
||||
except Exception:
|
||||
log.exception("Error fetching more post user list items for %s", self.name)
|
||||
except Exception as e:
|
||||
log.error("Error fetching more post user list items for %s: %s", self.name, e)
|
||||
|
||||
def remove_buffer(self, force=False):
|
||||
if not force:
|
||||
|
||||
Reference in New Issue
Block a user