/
RSS feedparser.py
198 lines (100 loc) · 3.65 KB
/
RSS feedparser.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import webbrowser
import feedparser
import linecache
import os
####https://kickass.unblocked.li/usearch/%22DC%20Week%2B%22/?rss=1.xml
def Fetchnextentry(currentnum,url):
print("\n\n")
ent=currentnum+1
d = feedparser.parse(url)
print("Next Entry\n",d["entries"][ent]["title"],"-",d["entries"][ent]["link"])
print("ADD TORRENT Y/N --OR press enter for next result")
YN=input()
if YN=="":
Fetchnextentry(ent,url)
elif (YN=="Y") or (YN=="y"):
magnet=d.entries[ent].torrent_magneturi
webbrowser.open_new_tab(magnet)
file="RSSDATA/"+RSS+".txt"
with open(file, "w") as file:
file.writelines(d["entries"][ent]["title"])
elif (YN=="N") or (YN=="n"):
return
else:
FetchLatestKATTorrrent(RSS+" "+YN)
def FetchLatestKATTorrrent(RSS):
os.system('cls' if os.name == 'nt' else 'clear')
ent=0
if int==True:
RSS=RSS[:-1]
print(RSS)
RSS=RSS.replace (" ", "%20") ##CONVERT SPECIAL ASCII IN INPUT TO HEXIDECIMAL
url="https://kickass.unblocked.li/usearch/"+RSS+"/?rss=1.xml"
#print(url)
d = feedparser.parse(url)
print("Latest entry\n",d["entries"][ent]["title"],"-",d["entries"][ent]["link"])
lastdate=linecache.getline("RSSDATA/"+RSS+".txt", 1)
lastdate=lastdate[:-1]
#print(lastdate)
#(d.entries[0].updated) ##checks for update to item
##USE REGEX TO FIND ISSUE NUMBER IN FEED TITLE
# !=lastdate:
# print("New entry, adding torrent")
# with open("RSSDATA/"+RSS+".txt", "w") as file:
# file.writelines(d.entries[0].updated)
print("ADD TORRENT Y/N --OR press enter for next result")
YN=input()
if YN=="":
Fetchnextentry(ent,url)
##MAKE SHIT RECURSIVE!!
elif (YN=="Y") or (YN=="y"):
magnet=d.entries[ent].torrent_magneturi
webbrowser.open_new_tab(magnet)
# file = open("RSS.txt, "w")
# file.write("SHOWNAME:")
RSS=RSS.replace ("\"", "")
file="RSSDATA/"+RSS+".txt"
with open(file, "w") as file:
file.writelines(d["entries"][ent]["title"])
elif (YN=="N") or (YN=="n"):
return
else:
FetchLatestKATTorrrent(RSS+" "+YN)
##FETCH SECOND ENTRY1
#if CHECK FOR PLAIN TEXT OR 3 DIGITS
def fetchfromlistfile():
numofcomics= int(linecache.getline("RSSDATA/list.txt", 1))
print(numofcomics,"Items in list file\n\n")
x=2
while x<=numofcomics+1:
print(x-1,". ",linecache.getline("RSSDATA/list.txt", x),sep='')
itemname=linecache.getline("RSSDATA/list.txt", x)
itemname=itemname[:-1]
lastfile=itemname+".txt"
lastfile="RSSDATA/"+lastfile
#print("read",lastfile)
last=linecache.getline(lastfile, 1)
if last!="":
print ("Last Download::",last)
x += 1
return numofcomics
numofcomics=fetchfromlistfile()
print("Enter number of item to select or type new search term")
userInput=input()
try:
intenter = int(userInput)
except ValueError:
int=False
if int==False:
FetchLatestKATTorrrent(userInput)
print("Entered term doesn't seem to be in list, would you like to add it? (I didn't check much)")
print("BRIDGE OUT")
elif intenter<=numofcomics:
RSS=linecache.getline("RSSDATA/list.txt", intenter+1)
RSS=RSS[:-1]
FetchLatestKATTorrrent(RSS)
else:
print("Input out of range")
#TODO option to Add input thats not in list to list
#TODO Error handling for invalid urls (Feedparser out of range)
#KATRSScheck("https://kickass.unblocked.li/usearch/%22DC%20Week%2B%22/?rss=1.xml")