from xml.dom.minidom import parse from urllib import urlopen, urlretrieve from sys import argv from re import compile, I from os.path import exists, basename from os import symlink, getcwd from time import strftime LINK_DIR = "/home/hddfsdk/Desktop" patterns = [compile(p.strip(), I) for p in open(argv[2]) if p[0] != '#'] rss = parse(urlopen(argv[1])) def child(no, na): return no.getElementsByTagName(na)[0].firstChild.data for i in rss.getElementsByTagName("item"): url = child(i, "link") hashed_file = "%d.torrent" % url.__hash__() fancy_path = "%s/%s" % (LINK_DIR, basename(url)[:basename(url).rfind("?")]) if not exists(hashed_file): for p in patterns: if p.search(child(i, "title")): print "%s: Downloading %s.torrent..." % \ (strftime("%a, %d %b %Y %H:%M:%S"), child(i, "title")), urlretrieve(child(i, "link"), hashed_file) symlink("%s/%s" % (getcwd(), hashed_file), fancy_path) print "done" break