This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
xbus-502-rss-template.py
78 lines (58 loc) · 2.12 KB
/
xbus-502-rss-template.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
"""
Template for RSS exercise
"""
##########################################################################
## Imports
##########################################################################
import os
import re
from pprint import pprint
import requests
import feedparser
##########################################################################
## Module Variables/Constants
##########################################################################
RSS_URL = 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml'
##########################################################################
## Functions
##########################################################################
def slugify(value):
"""
Converts to ASCII. Converts spaces to hyphens. Removes characters that
aren't alphanumerics, underscores, or hyphens. Converts to lowercase.
Also strips leading and trailing whitespace.
In short, this function converts text into a form safe to use as a
filename.
"""
value = value.encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
return re.sub('[-\s]+', '-', value)
def save_article(title, content):
"""
Save HTML content using a slugged version of the title as the basis for
the filename
"""
pass
def main():
"""
Main execution
"""
# grab RSS data and parse it
pass
# use pprint (pretty print) to print the formatted version of a variable
# if you would like to better understand what it contains
# pprint(SOME_PYTHON_VARIABLE)
# loop through each article/RSS item
for entry in entries:
# fetch the article using its url and include the header dictionary shown here:
# requests.get(URL_HERE, headers={"user-agent":"curl/7.86.0"})
pass
# save to disk or print an error message
# hint: save_article(content)
pass
##########################################################################
## Execution
##########################################################################
if __name__ == '__main__':
main()