summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2022-02-24 21:36:50 -0600
committerMark Powers <mark@marks.kitchen>2022-02-24 21:36:50 -0600
commit10593b1e128e37c3899eae78ac4dcce776f3ab81 (patch)
treecd35ca8c390256c4ce3efbc2d036a53e4effc322
parent3971685c60ac09eb8087db1c35e8c880de297cad (diff)
Fix old newsHEADmaster
-rw-r--r--on_this_day.py23
-rw-r--r--test.py2
2 files changed, 14 insertions, 11 deletions
diff --git a/on_this_day.py b/on_this_day.py
index da70cd8..970cec9 100644
--- a/on_this_day.py
+++ b/on_this_day.py
@@ -10,16 +10,19 @@ from config import config
def get_old_news():
print("getting old news")
year = int(date.today().strftime("%Y")) - 100
- century_ago = str(year) + date.today().strftime("-%m-%d")
- news_text = ""
- urls = config["news"]["urls"].split(",")
- names = config["news"]["names"].split(",")
- for i in range(len(urls)):
- full_url = urls[i] % century_ago
- name = names[i]
- if requests.get(full_url).status_code != 404:
- news_text += '<div><a href="%s">%s %s</a></div>\n' % (full_url, name, century_ago)
- return news_text or "No old news"
+ century_ago = date.today().strftime("%d%%2F%m%%2F") + str(year)
+
+ url = f"https://chroniclingamerica.loc.gov/search/pages/results/?state=Illinois&lccn=sn84031489&lccn=sn84031490&lccn=sn84031492&lccn=sn84025828&lccn=sn90053126&lccn=sn91055768&lccn=sn87062321&lccn=sn82014064&lccn=sn86056950&lccn=sn84025819&lccn=sn91055455&dateFilterType=range&date1={century_ago}&date2={century_ago}&language=&ortext=&andtext=&phrasetext=&proxtext=&proxdistance=5&rows=1&searchType=advanced&sequence=1"
+
+ r = requests.get(url)
+ soup = BeautifulSoup(r.text, features="lxml")
+ try:
+ href = soup.select(".highlite a")[0]["href"]
+ link = "https://chroniclingamerica.loc.gov" + href
+ return f'<div><a href="{link}">Old Chicago News from {year}</a></div>'
+ except:
+ pass
+ return "No old news"
def get_today_wikipedia():
print("getting today's wikipedia")
diff --git a/test.py b/test.py
index e66be5d..5763e67 100644
--- a/test.py
+++ b/test.py
@@ -1,3 +1,3 @@
import on_this_day
-print(on_this_day.get_week_holidays())
+print(on_this_day.get_old_news())