~aisrael/charms/precise/kusabax/charm-proof

« back to all changes in this revision

Viewing changes to bin/parse_upstream.py

  • Committer: Chris Hardee
  • Date: 2012-04-06 00:57:35 UTC
  • Revision ID: shazzner@gmail.com-20120406005735-sqhjq5xwqyfyzzpd
Finished changes as per Marco's suggestions. Thanks Marco! :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import urllib2
 
3
import xml.etree.cElementTree as et
 
4
import re
 
5
 
 
6
dic = {
 
7
        "media:hash" : "hash",
 
8
        "media:content" : "media"
 
9
}
 
10
 
 
11
def multiple_replace(dic, text):
 
12
        pattern = "|".join(map(re.escape, dic.keys()))
 
13
        return re.sub(pattern, lambda m: dic[m.group()], text)
 
14
 
 
15
f = urllib2.urlopen("https://sourceforge.net/api/file/index/project-id/241033/mtime/desc/limit/40/rss")
 
16
 
 
17
xml = et.XML(multiple_replace(dic, f.read()))
 
18
 
 
19
url = ""
 
20
hash = ""
 
21
 
 
22
for node in xml.iter("item"):
 
23
        url = node.findtext("link")
 
24
        for a in node.iter("media"):
 
25
                hash = a.findtext("hash")
 
26
        if "_full" in node.findtext("title") and url and hash:
 
27
                break
 
28
print url + "|" + hash