-
Notifications
You must be signed in to change notification settings - Fork 20
/
wikipedia.py
42 lines (36 loc) · 1.27 KB
/
wikipedia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import feedparser
import bs4
from typing import List
from ..util import PlacementPreference
from .storyprovider import StoryProvider
from ..story import Story
class WikipediaCurrentEventsStoryProvider(StoryProvider):
"""
A story provider that reads from today's current events on Wikipedia.
"""
def __init__(self):
pass
def get_stories(self, limit: int = 10, **kwargs) -> List[Story]:
"""
Get a list of current stories from Wikipedia.
"""
feed = feedparser.parse("https://www.to-rss.xyz/wikipedia/current_events/")
# title = feed.entries[0].title
title = "Today's Current Events"
content = bs4.BeautifulSoup(feed.entries[0].summary, "lxml")
for a in content.find_all("a"):
while a.find("li"):
a.find("li").replace_with_children()
while a.find("ul"):
a.find("ul").replace_with_children()
a.replace_with_children()
while content.find("dl"):
content.find("dl").name = "h3"
return [
Story(
headline=title,
body_html=str(content),
byline="Wikipedia Current Events",
placement_preference=PlacementPreference.BANNER,
)
]