replaced euobserver with its rss feed and added generic rss feed support

This commit is contained in:
thecookingsenpai 2024-01-13 01:14:10 +01:00
parent 35969b087d
commit 92f26cb193
7 changed files with 39 additions and 35 deletions

View File

@ -1,15 +1,5 @@
PPLX_API_KEY="your perplexity ai key"
MODEL="pplx-7b-chat"
NEWS="world-news"
POSSIBLE_NEWS_VALUES= '
"world-news",
"us-news",
"politics",
"sports",
"entertainment",
"business",
"science",
"ap-fact-check",
"oddities",
"health"
'
ENABLED_RSS="
'https://xml.euobserver.com/rss.xml',
"

View File

@ -13,7 +13,7 @@ MySides is a personal tool designed to scrape news from various sources. Please
## Built-in sites
[x] APNews (world news)
[x] EuObserver (rss feed)
[x] Any RSS feed (by adding it to the .env file)
## Work In Progress

File diff suppressed because one or more lines are too long

View File

@ -1,13 +0,0 @@
import feedparser
def fetchAndDigest():
links = []
feed = feedparser.parse("https://xml.euobserver.com/rss.xml")
for entry in feed.entries:
article_title = entry.title
article_link = entry.link
links.append([article_title, article_link])
print("[+] Total news: " + str(len(links)))
return links

View File

@ -1,9 +1,7 @@
#!/bin/bash
pip install -r requirements.txt
mkdir news
cp .env.example .env
echo "You should now open your .env file and insert your Perplexity API Key."
echo "You can get one at: https://www.perplexity.ai/settings/api"
echo "Then, launch main.py and wait for it to finish."
echo "allsides.html contains an overview of all the news."

View File

@ -3,7 +3,7 @@ from dotenv import load_dotenv
# Our modules
import apnews
import euobserver
import rss
import summarizer
load_dotenv()
@ -42,9 +42,13 @@ def transform_links(links):
def extract_data():
links = []
# Add your rss link to the .env file
rss_links = os.getenv("ENABLED_RSS").split(",")
links.extend(rss.fetchAndDigest(rss_links))
# Plug in your module here (links.extend(your_module.fetchAndDigest())
# TODO Programmatically scan and import modules
links.extend(apnews.fetchAndDigest())
links.extend(euobserver.fetchAndDigest())
print("[+] Total news: " + str(len(links)))
datas = transform_links(links)

21
rss.py Normal file
View File

@ -0,0 +1,21 @@
import feedparser
def fetchAndDigest(rss_feeds):
links = []
for rss_url in rss_feeds:
rss_url = rss_url.replace("'", "")
print("[+] Fetching RSS feed: " + rss_url)
links.extend(fetchAndDigest_subroutine(rss_url))
return links
def fetchAndDigest_subroutine(rss_url):
links = []
feed = feedparser.parse(rss_url)
for entry in feed.entries:
article_title = entry.title
article_link = entry.link
links.append([article_title, article_link])
print("[+] Total news: " + str(len(links)))
return links