From aa2fbdc4799c17a117643dd4e191fbfd7624bfbf Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 5 Jun 2025 15:12:45 +0200 Subject: [PATCH] Add feed reading --- prophet/app.py | 25 ++++++- pyproject.toml | 1 + test/resources/feed.atom | 157 +++++++++++++++++++++++++++++++++++++++ uv.lock | 20 +++++ 4 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 test/resources/feed.atom diff --git a/prophet/app.py b/prophet/app.py index bd8bf5e..2d3174f 100644 --- a/prophet/app.py +++ b/prophet/app.py @@ -3,11 +3,18 @@ from dataclasses import dataclass from datetime import datetime from uuid import uuid4 + +import feedparser from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from groq import Groq + +BEE_FEED = "https://babylonbee.com/feed" +BEE_FEED_TEST = "test/resources/feed.atom" # NOTE: Switch out when done testing + + @dataclass class Original: # BadJoke: Sting id: str # should probably be a sha256sum of the title/link? @@ -25,6 +32,12 @@ class Improvement: # GoodJoke: Queen id: str = str(uuid4()) + +def grab_latest_stings() -> list[str]: + feed: feedparser.FeedParserDict = feedparser.parse(BEE_FEED_TEST) # noqa: F841 + return feed.entries + + def improve_with_groq(original: str) -> str: client = Groq(api_key=os.getenv("GROQ_API_KEY", "NO_API_KEY_FOUND")) @@ -70,12 +83,18 @@ app.add_middleware( ) -@app.get("/test") @app.get("/improve") def improve_headline(content: str): return improve_with_groq(content) + +@app.get("/improvement") +def improve_headline(content: str): + return improve_with_groq(content) + + +@app.get("/testanswer") def read_root(): response = { "data": [ @@ -107,7 +126,9 @@ def read_root(): def start() -> None: from uvicorn import run - run("prophet.app:app", reload=True) + print(grab_latest_stings()) + + # run("prophet.app:app", reload=True) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 912aeb5..2830343 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ readme = "README.md" requires-python = ">=3.13" dependencies = [ "fastapi[standard]>=0.115.12", + "feedparser>=6.0.11", "groq>=0.26.0", ] diff --git a/test/resources/feed.atom b/test/resources/feed.atom new file mode 100644 index 0000000..6fb1957 --- /dev/null +++ b/test/resources/feed.atom @@ -0,0 +1,157 @@ + + + + Babylon Bee + + https://babylonbee.com + Your Trusted Source for Christian News Satire. + Thu, 05 Jun 2025 10:46:13 -0400 + en-US + hourly + 1 + + + https://media.babylonbee.com/articles/62bb34ba2e4f062bb34ba2e4f1.jpg + Babylon Bee + https://babylonbee.com + 32 + 32 + + + + Federal Judge Blocks Deportation Of Terrorist's Family, Orders Jews Lit Back On Fire + https://babylonbee.com/news/federal-judge-blocks-deportation-of-terrorists-family-orders-jews-lit-back-on-fire/ + Wed, 04 Jun 2025 19:30:39 -0400 + + + + + https://babylonbee.com/news/federal-judge-blocks-deportation-of-terrorists-family-orders-jews-lit-back-on-fire +

BOULDER, CO — Federal Judge Gordon Gallagher issued an emergency ruling blocking the deportation of the terrorist Mohamed Soliman and ordering the Jewish people he burned to be set back on fire.

+ ]]>
+
+ + + + + + Worship Pastor Makes Praise Songs More Accessible By Removing All References To ‘God’ And ‘Jesus’ + https://babylonbee.com/news/worship-pastor-makes-praise-songs-more-accessible-by-removing-all-references-to-god-and-jesus/ + Wed, 04 Jun 2025 17:08:40 -0400 + + + + + https://babylonbee.com/news/worship-pastor-makes-praise-songs-more-accessible-by-removing-all-references-to-god-and-jesus +

PLACENTIA, CA — In a move lauded by progressive Christians, a local worship pastor revealed that he had made praise songs more accessible by removing all references to God and Jesus.

+ ]]>
+
+ + + + + + 8 Hacks Girls Can Use To Win Track Meets In California + https://babylonbee.com/news/8-hacks-girls-can-use-to-still-win-track-meets-in-california/ + Wed, 04 Jun 2025 17:00:54 -0400 + + + + + https://babylonbee.com/news/8-hacks-girls-can-use-to-still-win-track-meets-in-california +

It's not easy for girls to win a track meet in California these days, what with dudes now allowed to compete. But there is hope! Here are eight hacks young ladies can use against their male competitors to still come out victorious on the track:

+ ]]>
+
+ + + + + + ‘Can You Bring Me A Glass Of Water Since You’re Up?’ Wife Asks Sleeping Husband + https://babylonbee.com/news/can-you-bring-me-a-glass-of-water-since-youre-up-wife-asks-sleeping-husband/ + Wed, 04 Jun 2025 14:41:59 -0400 + + + + + https://babylonbee.com/news/can-you-bring-me-a-glass-of-water-since-youre-up-wife-asks-sleeping-husband +

HARRISBURG, PA — According to sources, local wife and mother Karen Milton asked her sleeping husband to get her a glass of water Tuesday night, adding that she was only asking since he was already up and about.

+ ]]>
+
+ + + + + + Scholars Now Believe Prophet Elijah Was Caught Up Into Heaven In A Fiery 1977 Pontiac Trans Am + https://babylonbee.com/news/scholars-now-believe-prophet-elijah-was-caught-up-into-heaven-in-a-fiery-1977-pontiac-trans-am/ + Wed, 04 Jun 2025 13:46:51 -0400 + + + + + https://babylonbee.com/news/scholars-now-believe-prophet-elijah-was-caught-up-into-heaven-in-a-fiery-1977-pontiac-trans-am +

OXFORD — According to the distinguished scholars at Oxford University, the story of the prophet Elijah being caught up to Heaven in a fiery chariot may be inaccurate. Instead, it is more plausible that Elijah was transported in a 1977 Pontiac Firebird Trans Am.

+ ]]>
+
+ + + + + + Republicans Announce Plan To Keep Doing Opposite Of What Everyone Voted For Them To Do + https://babylonbee.com/news/republicans-announce-plan-to-keep-doing-opposite-of-what-everyone-voted-for-them-to-do/ + Wed, 04 Jun 2025 13:41:02 -0400 + + + + + https://babylonbee.com/news/republicans-announce-plan-to-keep-doing-opposite-of-what-everyone-voted-for-them-to-do +

WASHINGTON, D.C. — Congressional Republicans have unveiled plans to continue doing the exact opposite of what everyone voted for them to do.

+ ]]>
+
+ + + + + + Democrats Warn Deporting Illegal Terrorist Family Could Be Slippery Slope To Deporting Other Illegal Terrorist Families + https://babylonbee.com/news/democrats-warn-deporting-illegal-terrorist-family-could-be-slippery-slope-to-deporting-other-illegal-terrorist-families/ + Wed, 04 Jun 2025 13:16:37 -0400 + + + + + https://babylonbee.com/news/democrats-warn-deporting-illegal-terrorist-family-could-be-slippery-slope-to-deporting-other-illegal-terrorist-families +

WASHINGTON, D.C. — As part of a growing outcry over Trump's immigration policy, Democrats warned that deporting an illegal terrorist family could be a slippery slope to deporting other illegal terrorist families.

+ ]]>
+
+ + + + + + USS Harvey Milk To Be Renamed 'USS No Homo' + https://babylonbee.com/news/uss-harvey-milk-to-be-renamed-uss-no-homo/ + Wed, 04 Jun 2025 11:34:11 -0400 + + + + + https://babylonbee.com/news/uss-harvey-milk-to-be-renamed-uss-no-homo +

WASHINGTON, D.C. — The United States Navy announced this morning that the USS Harvey Milk will be officially renamed the USS No Homo.

+ ]]>
+
+ + + + +
+
\ No newline at end of file diff --git a/uv.lock b/uv.lock index 5035527..5519cc8 100644 --- a/uv.lock +++ b/uv.lock @@ -128,6 +128,18 @@ standard = [ { name = "uvicorn", extra = ["standard"] }, ] +[[package]] +name = "feedparser" +version = "6.0.11" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "sgmllib3k" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ff/aa/7af346ebeb42a76bf108027fe7f3328bb4e57a3a96e53e21fd9ef9dd6dd0/feedparser-6.0.11.tar.gz", hash = "sha256:c9d0407b64c6f2a065d0ebb292c2b35c01050cc0dc33757461aaabdc4c4184d5", size = 286197, upload-time = "2023-12-10T16:03:20.854Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7c/d4/8c31aad9cc18f451c49f7f9cfb5799dadffc88177f7917bc90a66459b1d7/feedparser-6.0.11-py3-none-any.whl", hash = "sha256:0be7ee7b395572b19ebeb1d6aafb0028dee11169f1c934e0ed67d54992f4ad45", size = 81343, upload-time = "2023-12-10T16:03:19.484Z" }, +] + [[package]] name = "groq" version = "0.26.0" @@ -311,6 +323,7 @@ version = "0.1.0" source = { editable = "." } dependencies = [ { name = "fastapi", extra = ["standard"] }, + { name = "feedparser" }, { name = "groq" }, ] @@ -323,6 +336,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "fastapi", extras = ["standard"], specifier = ">=0.115.12" }, + { name = "feedparser", specifier = ">=6.0.11" }, { name = "groq", specifier = ">=0.26.0" }, ] @@ -471,6 +485,12 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/44/42/d58086ec20f52d2b0140752ae54b355ea2be2ed46f914231136dd1effcc7/ruff-0.11.12-py3-none-win_arm64.whl", hash = "sha256:65194e37853158d368e333ba282217941029a28ea90913c67e558c611d04daa5", size = 10697770, upload-time = "2025-05-29T13:31:38.009Z" }, ] +[[package]] +name = "sgmllib3k" +version = "1.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9e/bd/3704a8c3e0942d711c1299ebf7b9091930adae6675d7c8f476a7ce48653c/sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9", size = 5750, upload-time = "2010-08-24T14:33:52.445Z" } + [[package]] name = "shellingham" version = "1.5.4"