-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfeeds.py
52 lines (40 loc) · 1.24 KB
/
cfeeds.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
# script to parse Chris Coyiers favorite feeds
# makes an OPML file for importing into readers
#
# author: Hamish Macpherson
# url: http://hami.sh/
# created: 11-May-2011
import urllib2, re
OPML_TEMPLATE_TOP = """
<opml version="1.0">
<head>
<title>Chris Coyier's Favorite Blogs</title>
</head>
<body>
"""
OPML_TEMPLATE_ITEM = """<outline text="{feedtitle}" title="{feedtitle}" type="rss" xmlUrl="{feedurl}" htmlUrl="{siteurl}"/>\n"""
OPML_TEMPLATE_BOTTOM = """
</body>
</opml>
"""
page = urllib2.urlopen("http://css-tricks.com/blogs-i-read/")
page = page.read()
# Format of each site/feed
# Will not match sites w/out a feed
rexp = re.compile("""<div
class="person"> (.*?) <a
href="(.*?)">Website</a> <a
href="(.*?)">Feed</a></div""")
feeds = re.findall(rexp, page)
opml = open("coyier-subscriptions.xml", "w")
opml.write(OPML_TEMPLATE_TOP)
try:
for f in feeds:
info = {'feedtitle': f[0], 'siteurl': f[1], 'feedurl': f[2]}
xmldata = OPML_TEMPLATE_ITEM.format(**info)
opml.write(xmldata)
except:
print "Error in processing feeds."
opml.write(OPML_TEMPLATE_BOTTOM)
opml.close()
print "Succuessfully wrote OPML file: coyier-subscriptions.xml"