forked from shauryachawla/feedr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (50 loc) · 1.62 KB
/
app.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
import sys
import feedparser
from colorama import init
from colorama import Back, Style
init(autoreset=True)
# print(Fore.RED + 'some red text')
# print('automatically back to default color again')
def latest():
d = feedparser.parse(url)
print (Back.RED + "Title:") + (Style.RESET_ALL + " " + d.entries[0].title)
print (Back.YELLOW + "Link:") + (Style.RESET_ALL + " " + d.entries[0].link)
def latest_five():
d = feedparser.parse(url)
i = 0
for i in range(0, 5):
print (Back.CYAN + str(i + 1) + ")" + Style.RESET_ALL + " " +
Back.RED + "Title:" +
(Style.RESET_ALL + " " + d.entries[i].title))
print (' '*(len(str(i+1))) + ' ' + Back.YELLOW + "Link:" +
(Style.RESET_ALL + " " + d.entries[i].link))
# print "Content: " + d.entries[i]['content']
def show(title, link, desc):
print str(title)
# print str(date)
print str(link)
print str(desc)
def menu():
print "What do you wish to do now?"
print "1. Access the most recent item from your feed"
print "2. Access the 5 most recent items from your feed."
opt = int(raw_input('Choice: '))
if opt == 1:
latest()
elif opt == 2:
latest_five()
else:
print "Not a valid choice"
exit(0)
def check_args():
if len(sys.argv) != 2:
print "Usage: python app.py input_RSS_URL\n"
exit(0)
if not sys.argv[1].endswith('xml'):
print 'Your URL should point to an XML file.'
print 'Usage: python app.py input_RSS_URL\n'
exit(0)
if __name__ == "__main__":
check_args()
url = sys.argv[1]
menu()