Created
March 4, 2024 21:52
-
-
Save lukeswitz/847f11ef93c4f61fabea78b28185f13d to your computer and use it in GitHub Desktop.
Fetch the latest top ten trending words from Wikipedia Top 25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
import subprocess | |
def fetch_trending_topics(): | |
url = "https://en.wikipedia.org/wiki/Wikipedia:Top_25_Report" | |
response = requests.get(url) | |
soup = BeautifulSoup(response.content, 'html.parser') | |
topics = [] | |
for item in soup.select("h3 + ul")[0].select("li"): | |
topic = item.get_text(separator=" ", strip=True) | |
topics.append(topic) | |
return topics[:10] | |
def append_topics_to_file_with_anew(topics, file_path): | |
for topic in topics: | |
subprocess.run(['anew', file_path], input=topic.encode()) | |
file_path = '/mnt/data/trending_topics.txt' | |
trending_topics = fetch_trending_topics() | |
append_topics_to_file_with_anew(trending_topics, file_path) | |
file_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment