-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_series.py
53 lines (40 loc) · 1.43 KB
/
get_series.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
from icalendar import Calendar
from PyRSS2Gen import RSSItem, RSS2
import re,urllib,feedparser
ICAL_URL = 'http://www.pogdesign.co.uk/cat/download_ics/dd1cc774b062db1df0a594402f3ac10b'
url = urllib.urlopen(ICAL_URL)
cal = Calendar.from_string(url.read())
events = cal.walk('VEVENT')
p = re.compile('(.*) Episodes, TV Shows')
series = []
for event in events:
serie = event.get('CATEGORIES')
serie = p.match(serie).groups()[0].strip()
series.append(serie)
series = list(set(series))
print series
# generate the rss urls
hit_list = []
for name in series:
name = urllib.quote(name)
feed = feedparser.parse('http://ezrss.it/search/index.php?show_name=%s&quality=720p&mode=rss'%name)
if len(feed['items'])==0:
feed = feedparser.parse('http://ezrss.it/search/index.php?show_name=%s&mode=rss'%name)
print feed.url
hit_list.append(feed)
# get the feeds and join them in one big list
feeds = hit_list
print "Found",len(feeds),"feeds."
entries = []
for feed in feeds:
entries.extend(feed['items'])
# this section is for sorting the entries
decorated = [(entry["date_parsed"], entry) for entry in entries]
decorated.sort()
decorated.reverse()
entries = [entry for (date,entry) in decorated]
items = [RSSItem(**item) for item in entries]
feeds = RSS2(title="My series feed",description="This feed is an aggregation of various feeds",link="",items = items)
f = open('feed.xml','w')
f.write(feeds.to_xml())
f.close()