tested for http requests (404s)

This commit is contained in:
likhy 2023-04-30 10:32:50 -07:00
parent 9905a15ace
commit d8c4cb47fa
2 changed files with 20 additions and 12 deletions

View File

@ -1,4 +1,5 @@
latestpage="result.html" # latestpage="result.html"
latestpages=["meta.json", "result.html"]
[page] [page]
postsperpage = 20 postsperpage = 20

View File

@ -374,24 +374,27 @@ if __name__ == "__main__":
print(json.dumps(profile), file=f) print(json.dumps(profile), file=f)
import urllib.request as http 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): def fetch(follow_list):
oither_people = [] other_people = []
for someone in follow_list: for someone in follow_list:
try: try:
with http.urlopen(someone) as response: with http.urlopen(someone) as response:
data = response.read() data = response.read()
objects.append(json.loads(data)) objects.append(json.loads(data))
except urllib.error.HTTPError: except http.HTTPError as e:
print("http error - skipping", file=sys.stderr) print(e,": ", someone, file=sys.stderr)
pass pass
return other_people return other_people
list_of_json_objs = [] # list_of_json_objs = []
with open("meta.json",'r') as f: # with open("meta.json",'r') as f:
list_of_json_objs.append(json.loads(f.read())) # list_of_json_objs.append(json.loads(f.read()))
# list_of_json_obj = fetch(config["profile"]["following"]) list_of_json_objs = fetch(webring_config["list"])
if list_of_json_objs == []:
print("no remote profiles loaded", file=sys.stderr)
return []
rendered = [] rendered = []
template = config["format"] template = webring_config["format"]
SHORT_BIO_LIMIT = 150 SHORT_BIO_LIMIT = 150
for profile in list_of_json_objs: for profile in list_of_json_objs:
epoch_timestamp = profile["last-updated"] epoch_timestamp = profile["last-updated"]
@ -456,13 +459,17 @@ if __name__ == "__main__":
len(p), p[0].get_epoch_time(), cfg["webring"] ) len(p), p[0].get_epoch_time(), cfg["webring"] )
if "following" in cfg["webring"]: if "following" in cfg["webring"]:
fellows = fn1(cfg["webring"]["following"] ) fellows = fn1(cfg["webring"]["following"] )
updated += writepage( if fellows != []:
tpl, fellows, tc, cfg["page"], subdir="placeholder" ) updated += writepage(
tpl, fellows, tc, cfg["page"], subdir="placeholder" )
with open("updatedfiles.txt", 'w') as f: with open("updatedfiles.txt", 'w') as f:
for filename in updated: for filename in updated:
print(filename, file=f) # sys.stderr) print(filename, file=f) # sys.stderr)
if "latestpage" in cfg: if "latestpage" in cfg:
print(cfg["latestpage"], file=f) print(cfg["latestpage"], file=f)
if "latestpages" in cfg:
for page in cfg["latestpages"]:
print(page, file=f)
try: try:
main() main()
except KeyError as e: except KeyError as e: