From 6fc0162deea2f6e02de026228df28ad3181d24a9 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 7 Mar 2013 21:13:06 -0800 Subject: [PATCH] added extension to autoProcessGames.py --- autoProcessGames | 97 ------------------------------------------------ 1 file changed, 97 deletions(-) delete mode 100644 autoProcessGames diff --git a/autoProcessGames b/autoProcessGames deleted file mode 100644 index a5fa6d89..00000000 --- a/autoProcessGames +++ /dev/null @@ -1,97 +0,0 @@ -import sys -import urllib -import os -import shutil -import ConfigParser -import datetime -import time -import json -import logging - -from nzbToMediaEnv import * - -Logger = logging.getLogger() - -class AuthURLOpener(urllib.FancyURLopener): - def __init__(self, user, pw): - self.username = user - self.password = pw - self.numTries = 0 - urllib.FancyURLopener.__init__(self) - - def prompt_user_passwd(self, host, realm): - if self.numTries == 0: - self.numTries = 1 - return (self.username, self.password) - else: - return ('', '') - - def openit(self, url): - self.numTries = 0 - return urllib.FancyURLopener.open(self, url) - -def process(dirName, nzbName=None, status=0): - - status = int(status) - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - Logger.info("Loading config from %s", configFilename) - - if not os.path.isfile(configFilename): - Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") - return 1 # failure - - config.read(configFilename) - - host = config.get("Gamez", "host") - port = config.get("Gamez", "port") - username = config.get("Gamez", "username") - password = config.get("Gamez", "password") - apikey = config.get("Gamez", "apikey") - - try: - ssl = int(config.get("Gamez", "ssl")) - except (ConfigParser.NoOptionError, ValueError): - ssl = 0 - - try: - web_root = config.get("Gamez", "web_root") - except ConfigParser.NoOptionError: - web_root = "" - - myOpener = AuthURLOpener(username, password) - - if ssl: - protocol = "https://" - else: - protocol = "http://" - - baseURL = protocol + host + ":" + port + web_root + "/api?api_key=" + apikey + "&mode=" - - fields = nzbName.split("-") - gamezID = fields[0].replace("[","").replace("]","").replace(" ","") - downloadStatus = 'Wanted' - if status == 0: - downloadStatus = 'Downloaded' - - URL = baseURL + "UPDATEREQUESTEDSTATUS&db_id=" + gamezID + "&status=" + downloadStatus - - Logger.debug("Opening URL: %s", url) - - try: - urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) - return 1 # failure - - result = json.load(urlObj) - Logger.info("Gamez returned %s", result) - if result['success']: - Logger.info("Status for %s has been set to %s in Gamez", gamezID, downloadStatus) - else: - Logger.error("Status for %s has NOT been updated in Gamez", gamezID) - return 1 # failure - - else: - Logger.info("The download failed. Nothing to process") - return 0 # Success (as far as this script is concerned)