From 932e39ac0a1bdd8ec55ae7c1ded663e0eb8edc95 Mon Sep 17 00:00:00 2001 From: magical Date: Mon, 8 Aug 2022 08:24:45 +0000 Subject: [PATCH] load overviews from cache to be nice and avoid hammering the server during development --- clients/nntp_client.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/clients/nntp_client.py b/clients/nntp_client.py index 71b6fb7..a51787a 100644 --- a/clients/nntp_client.py +++ b/clients/nntp_client.py @@ -97,7 +97,7 @@ class BBJNews(object): "admins": [], } - self.connect() + #self.connect() #try: # self.user = self("get_me")["data"] @@ -486,8 +486,15 @@ class BBJNews(object): author_id = thread["author"] print(usermap[author_id]["user_name"]) """ - response, count, first, last, name = self.conn.group(self.group) + if os.path.exists("overview_cache.bbj.json"): + with open("overview_cache.bbj.json", "rt") as f: + overviews = json.load(f) + else: + response, count, first, last, name = self.conn.group(self.group) + response, overviews = self.conn.over((first, None)) + with open("overview_cache.bbj.json", "wt") as f: + json.dump(overviews, f) # overviews is a list of (article_number, overview) tuples, # one for each article. @@ -499,10 +506,6 @@ class BBJNews(object): # :bytes - the number of bytes in the article # :lines - the number of lines in the body (deprecated) - response, overviews = self.conn.over((first, None)) - with open("overview_cache.bbj.json", "wt") as f: - json.dump(overviews, f) - if False: # build up a map of message references # we use a disjoint-set data structure