From d8c4cb47faf67c03931446792ca05c1558f30fb4 Mon Sep 17 00:00:00 2001 From: likhy Date: Sun, 30 Apr 2023 10:32:50 -0700 Subject: [PATCH] tested for http requests (404s) --- example/settings.toml | 3 ++- microblog.py | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/example/settings.toml b/example/settings.toml index 31c8daf..5a8f52b 100644 --- a/example/settings.toml +++ b/example/settings.toml @@ -1,4 +1,5 @@ -latestpage="result.html" +# latestpage="result.html" +latestpages=["meta.json", "result.html"] [page] postsperpage = 20 diff --git a/microblog.py b/microblog.py index b049c07..059c46f 100644 --- a/microblog.py +++ b/microblog.py @@ -374,24 +374,27 @@ if __name__ == "__main__": print(json.dumps(profile), file=f) import urllib.request as http - def fn1(config): # come up with better name later + def fn1(webring_config): # come up with better name later def fetch(follow_list): - oither_people = [] + other_people = [] for someone in follow_list: try: with http.urlopen(someone) as response: data = response.read() objects.append(json.loads(data)) - except urllib.error.HTTPError: - print("http error - skipping", file=sys.stderr) + except http.HTTPError as e: + print(e,": ", someone, file=sys.stderr) pass return other_people - list_of_json_objs = [] - with open("meta.json",'r') as f: - list_of_json_objs.append(json.loads(f.read())) - # list_of_json_obj = fetch(config["profile"]["following"]) + # list_of_json_objs = [] + # with open("meta.json",'r') as f: + # list_of_json_objs.append(json.loads(f.read())) + list_of_json_objs = fetch(webring_config["list"]) + if list_of_json_objs == []: + print("no remote profiles loaded", file=sys.stderr) + return [] rendered = [] - template = config["format"] + template = webring_config["format"] SHORT_BIO_LIMIT = 150 for profile in list_of_json_objs: epoch_timestamp = profile["last-updated"] @@ -456,13 +459,17 @@ if __name__ == "__main__": len(p), p[0].get_epoch_time(), cfg["webring"] ) if "following" in cfg["webring"]: fellows = fn1(cfg["webring"]["following"] ) - updated += writepage( - tpl, fellows, tc, cfg["page"], subdir="placeholder" ) + if fellows != []: + updated += writepage( + tpl, fellows, tc, cfg["page"], subdir="placeholder" ) with open("updatedfiles.txt", 'w') as f: for filename in updated: print(filename, file=f) # sys.stderr) if "latestpage" in cfg: print(cfg["latestpage"], file=f) + if "latestpages" in cfg: + for page in cfg["latestpages"]: + print(page, file=f) try: main() except KeyError as e: