-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrssreader
More file actions
99 lines (94 loc) · 2.69 KB
/
rssreader
File metadata and controls
99 lines (94 loc) · 2.69 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
from bs4 import BeautifulSoup
import os
import sys
def getFeed(url):
os.system('curl -s -o .page.html "'+ url +'"')
page = open('./.page.html')
soup = BeautifulSoup(page, 'html.parser')
items = soup.find_all('item')
i = len(items)
Links = ['']*(i+1)
for item in reversed(items):
title = "\033[92m {}\033[00m".format(item.title.string.encode("ascii", "ignore"))
link = "\033[93m {}\033[00m".format(item.link.string.encode("ascii", "ignore"))
Links[i] = item.link.string.encode("ascii", "ignore")
num = "\033[91m {}\033[00m".format(str(i))
print(num + ' ' + title + '\n' + link + '\n')
i -= 1
os.system('rm .page.html')
return Links
def displayNames(data, flag):
totaldata = []
i = 0
for line in data:
line = line.strip().split()
totaldata.append(line)
if flag == 1:
print i, line[0]
i += 1
return totaldata
def addData(data):
name = raw_input('Enter Name of the Feed : ')
url = raw_input('Enter URL of the Feed : ')
data.write(name + ' ' + url + '\n')
print 'Done.'
if __name__ == '__main__':
home = os.environ['HOME']
data = open(home+'/.myrsslinks.csv', 'a+')
tot = 0
if len(sys.argv) == 1:
totaldata = displayNames(data, 1)
if not totaldata:
print 'No data is present'
print 'to add use like rssreader --add'
exit()
sno = int(raw_input('Pick from above numbers: '))
try:
Links = getFeed(totaldata[sno][1])
except IndexError:
print 'Invalid number'
print 'to add use like rssreader --add'
exit()
elif len(sys.argv) == 2:
if 'http' in sys.argv[1]:
Links = getFeed(sys.argv[1])
elif sys.argv[1].isdigit():
totaldata = displayNames(data, 0)
sno = int(sys.argv[1])
try:
Links = getFeed(totaldata[sno][1])
except IndexError:
print 'No such number exists'
print 'to add use like rssreader --add'
exit()
elif sys.argv[1] == '--add':
addData(data)
exit()
print "*******\033[91m {}\033[00m *******\n".format(totaldata[sno][0])
print 'Pick the numbers to open in browser, * to open all and quit, 0 to quit'
print '<start no.> <end no.> or <no.> or *'
while 1:
tot = len(Links)
choice = raw_input('> ')
if choice == '*':
for i in range(1, tot):
os.system('firefox ' + Links[i])
break
else:
choice = map(int, choice.split())
if len(choice) == 1:
if choice[0] == 0:
break
if choice[0] > tot or choice[0] < 1:
print '> ERR'
else:
os.system('firefox ' + Links[choice[0]])
elif len(choice) >= 2:
if choice[0] > choice[1]:
choice[0], choice[1] = choice[1], choice[0]
if 0 < choice[0] and choice[1] < tot+1:
for i in range(choice[0], choice[1]+1):
os.system('firefox ' + Links[i])
else:
print '> ERR'