summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorMichael Yick <cavemanon@mail.snootgame.xyz>2023-02-27 16:37:04 -0600
committerMichael Yick <cavemanon@mail.snootgame.xyz>2023-02-27 16:37:04 -0600
commitb6a3264cc18fec0df3598e769c038410e3646720 (patch)
tree1a965bd209ffe313ffa4aab06fd0603a188fd97d /main.py
downloaddilbertRss-b6a3264cc18fec0df3598e769c038410e3646720.tar.gz
dilbertRss-b6a3264cc18fec0df3598e769c038410e3646720.tar.bz2
dilbertRss-b6a3264cc18fec0df3598e769c038410e3646720.zip
Inital Commit
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100755
index 0000000..be64396
--- /dev/null
+++ b/main.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import requests
+import bs4
+import time
+import feedgenerator
+import json
+from datetime import datetime, timedelta
+from fastapi import FastAPI, Response
+
+
+app = FastAPI()
+
+@app.get("/")
+async def root():
+ sneed = feedgenerator.Rss201rev2Feed(
+ title = "Dilbert Comic Strip",
+ description = "New 'bert",
+ link = ("https://dilbert.techchud.xyz/")
+ )
+
+ for day in range(0,7):
+ rawDate = datetime.today() - timedelta(days = day)
+ date = rawDate.strftime('%Y-%m-%d')
+ tries = 25
+ for i in range(tries):
+ search = requests.get("https://dilbert.com/strip/" + date)
+ if search.status_code == 503:
+ if i < tries - 1:
+ time.sleep(1)
+ continue
+ else:
+ raise
+ break
+
+ soup = bs4.BeautifulSoup(search.text, features="lxml")
+ comicTitle = soup.find("meta", property="og:title")["content"]
+ comicURL = soup.find("meta", property="og:image")["content"]
+ comicAuthor = soup.find("meta", property="article:author")["content"]
+ url = "https://dilbert.com/strip/" + date
+
+ sneed.add_item( title=comicTitle, description=comicURL, author_name=comicAuthor, link=url, id=id)
+
+ feed = sneed.writeString("utf-8")
+
+ return Response(content=feed, media_type="application/xml")
+