Compare commits

..

4 commits

Author SHA1 Message Date
ad81825bfe Merge pull request 'Fix bare excepts' (#14) from fix-bare-excepts into main
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
Reviewed-on: #14
2024-02-10 20:31:49 -08:00
3b1502e2df Merge branch 'main' into fix-bare-excepts
All checks were successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pull_request_closed/lint Pipeline was successful
2024-02-10 20:30:45 -08:00
11d7d4bcec Merge branch 'main' into fix-bare-excepts 2024-02-10 20:27:59 -08:00
3c3b580496 Fix bare excepts 2024-02-10 20:22:10 -08:00

View file

@ -1,5 +1,6 @@
import json
from datetime import datetime
from json.decoder import JSONDecodeError
from typing import Optional
import requests
@ -70,7 +71,7 @@ with Session(engine) as session:
schema_org = json.loads(schema_org_scriptblock.text)
assert schema_org["@context"] == "http://schema.org"
last_updated_time = datetime.fromisoformat(schema_org["dateModified"])
except:
except (AssertionError, JSONDecodeError):
print(
"Could not find or load schema.org data for this post, looking up the meta published time"
)
@ -80,7 +81,7 @@ with Session(engine) as session:
"meta", attrs={"property": "article:published_time"}
)["content"]
)
except:
except NameError:
print("Could not find or load the meta published time for this post")
last_updated_time = datetime.now()
@ -106,14 +107,14 @@ with Session(engine) as session:
article_record.dfp_targeting_id = article_soup.find(
"script", {"class": "dfp_targeting", "data-key": "id"}
)["data-value"]
except:
except NameError:
print("Could not find or load IDs for this post")
try:
tags = article_soup.find(
"script", {"class": "dfp_targeting", "data-key": "tags"}
)["data-value"].split("|")
except:
except NameError:
print("Could not find or load any tags for this article")
tags = []
@ -141,7 +142,7 @@ with Session(engine) as session:
article_record.post_id = mastodon_post_result["id"]
else:
print("Article has already been posted")
except:
except Exception:
print("Could not load a description/post this article")
article_record.article_link = article_link