Cache API results for better testing
Signed-off-by: Markus Birth <markus@birth-online.de>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import configparser
|
||||
import requests
|
||||
import os.path
|
||||
import pickle
|
||||
from collections.abc import Callable
|
||||
from atproto import Client, client_utils
|
||||
from rich import print
|
||||
@@ -16,6 +18,11 @@ class BlueBackBlocker():
|
||||
return self.agent.app.bsky.graph.get_lists({'actor': self.did})
|
||||
|
||||
def get_list(self, list_id: str, progress: Callable[[int, int], None] = None):
|
||||
cachefile = f"bs_{list_id}.pickle"
|
||||
if os.path.isfile(cachefile):
|
||||
with open(cachefile, "rb") as f:
|
||||
return pickle.load(f)
|
||||
|
||||
list_uri = f"at://{self.did}/app.bsky.graph.list/{list_id}"
|
||||
cursor = None
|
||||
members = []
|
||||
@@ -30,10 +37,15 @@ class BlueBackBlocker():
|
||||
if not r["cursor"]:
|
||||
break
|
||||
cursor = r["cursor"]
|
||||
return {
|
||||
results = {
|
||||
"items": members,
|
||||
"list": r["list"]
|
||||
}
|
||||
|
||||
with open(cachefile, "wb") as f:
|
||||
pickle.dump(results, f)
|
||||
|
||||
return results
|
||||
|
||||
def add_to_list(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user