def init(): if globals.site_config["backup_site"]: btsite.site_ktxp() global feed_url feed_url = btsite.host + btsite.feed_uri globals.write_log(0, "FEED: %s" % feed_url)
def connect(): global tc tc = transmissionrpc.Client(globals.trconfig["host"], port=globals.trconfig["port"], user=globals.trconfig["user"], password=globals.trconfig["password"]) globals.write_log(0, "Connected to Transmission RPC server at %s:%d" % (globals.trconfig["host"], globals.trconfig["port"]))
def parse(): try: feed = feedparser.parse(feed_url, agent=USER_AGENT); except: globals.write_log(1, "Failed to update feed") return 0 #check for update try: if globals.last_update_tag == feed["entries"][0]["updated"]: print "No update" globals.write_log(0, "No Update.") return 0 else: print "Updating" globals.write_log(0, "Checking RSS...") except: globals.write_log(1, "Failed to update feed") return 0 counter = 0 match = 0 #parse seed info for item in feed["entries"]: # for k, v in item.iteritems(): # print k, ":", v # print item["title"] if globals.last_update_tag == item["updated"]: #only check the updated part break print "Item: %s" % item["title"] if keyword_filter.check(item["title"]): match += 1 globals.add_seed_info(item["title"], get_post_link(item), get_seed_link(item), get_magnet_link(get_post_link(item))) counter += 1 # if check_keywords(keywords, item["title"]): # globals.add_seed_info(item["title"], # get_post_link(item), # get_seed_link(item), # get_magnet_link(get_post_link(item))) # print get_post_link(item) # print get_seed_link(item) # print get_magnet_link(get_post_link(item)) globals.write_log(0, "Checked %d new items" % counter, " %d seed post matches" % match) globals.last_update_tag = feed["entries"][0]["updated"] return match
def download_seed(seed_info): global tc try: if globals.site_config["torrent_file"]: tc.add(seed_info["seed"]) else: if globals.site_config["backup_site"]: tc.add_uri(seed_info["seed"]) else: tc.add_uri(seed_info["magnet"]) except transmissionrpc.error.TransmissionError, e: globals.write_log(1, e.message, "Error :\t%s" % seed_info["title"], "\t%s" % seed_info["post"], "\t%s" % seed_info["seed"][-41:], "\t%s" % seed_info["magnet"][:52]) return
def test(): try: feed = feedparser.parse(feed_url, agent=USER_AGENT); except: globals.write_log(1, "Failed to update feed") return 0 for k, v in feed.iteritems(): print k print "--------------------------------------------------" print feed["encoding"] for item in feed["entries"]: for k, v in item.iteritems(): print k, ":", v break # print check_keywords([tag_string], item["title"]) # print get_post_link(item) # print get_seed_link(item) # print get_magnet_link(get_post_link(item)) # break #check for update if globals.last_update_tag == feed["entries"][0]["updated"]: print "No update" globals.write_log(0, "No Update.") return False else: print "Updating" globals.write_log(0, "Checking RSS...") globals.last_update_tag = feed["entries"][0]["updated"]
global tc try: if globals.site_config["torrent_file"]: tc.add(seed_info["seed"]) else: if globals.site_config["backup_site"]: tc.add_uri(seed_info["seed"]) else: tc.add_uri(seed_info["magnet"]) except transmissionrpc.error.TransmissionError, e: globals.write_log(1, e.message, "Error :\t%s" % seed_info["title"], "\t%s" % seed_info["post"], "\t%s" % seed_info["seed"][-41:], "\t%s" % seed_info["magnet"][:52]) return globals.write_log(0, "Add :\t%s" % seed_info["title"], "\t%s" % seed_info["post"], "\t%s" % seed_info["seed"][-40:], "\t%s" % seed_info["magnet"][:52]) if __name__ == "__main__": print "transmission_control: Hello world." connect() tc.list()
import globals import rss_parse import transmission_control import keyword_filter import daemonize if __name__ == "__main__": cwd = os.getcwd() output = os.path.join(cwd, "rss-seeddl.log") pid_file = os.path.join(cwd, "rss-seeddl.pid") # daemonize.daemonize(stdout=output, stderr=output, pidfile=pid_file) os.chdir(cwd) # print "main: Hello world." globals.write_log(0, "Starting...", "") globals.init_configs("test_config.yaml") # keyword_filter.init_keywords_list(globals.rss_config["keywords_list"]) rss_parse.init() transmission_control.connect() globals.write_log(0, "Running...", "") while True: keyword_filter.init_keywords_list(globals.rss_config["keywords_list"]) ret = rss_parse.parse() if ret > 0: for seed in globals.seed_list: if globals.check_duplication(seed): transmission_control.download_seed(seed) time.sleep(globals.rss_config["update_period"] * 60)