-
Notifications
You must be signed in to change notification settings - Fork 0
/
top_5_cfc_news.py
34 lines (25 loc) · 941 Bytes
/
top_5_cfc_news.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
"""
The latest 5 items from the Official CFC website
"""
from datetime import datetime
import feedparser
def fetch_cfc_entries(url: str) -> list:
"""Fetches CFC entries from a given url"""
news_items = feedparser.parse(url)["entries"]
return [{
"title": entry["description"].replace("|", "-"),
"url": entry["link"].split("#")[0],
"published": convert_cfc_date(entry["published"]),
} for entry in news_items]
def convert_cfc_date(input_d: str) -> str:
"""Converts CFC's standard date format to a more readable format"""
working = datetime.strptime(input_d, "%a, %d %b %Y %H:%M:%S %z")
friendly_date = datetime.strftime(working, "%d %b")
return friendly_date
if __name__ == "__main__":
URL = "[source xml]"
entries = fetch_cfc_entries(URL)[:5]
OUTPUT = "".join([
f"- {entry['title']} - ({entry['published']})\n" for entry in entries
])
print(OUTPUT)