diff --git a/Gamez.py b/Gamez.py index 39cfe3c..ad50a3b 100644 --- a/Gamez.py +++ b/Gamez.py @@ -52,7 +52,8 @@ def RunWebServer(self,isToDaemonize): config = ConfigParser.RawConfigParser() config.read('Gamez.ini') interval = config.get('Scheduler','download_interval').replace('"','') - workerTask = cherrypy.process.plugins.BackgroundTask(interval,RunGameTask) + fInterval = float(interval) + workerTask = cherrypy.process.plugins.BackgroundTask(fInterval,RunGameTask) try: workerTask.start() cherrypy.quickstart(WebRoot(app_path),'/',config=conf) @@ -74,6 +75,8 @@ def GenerateSabPostProcessScript(): file.write("\n") file.write('import sys') file.write("\n") + file.write('import urllib') + file.write("\n") file.write('fields = str(sys.argv[3]).split("-")') file.write("\n") file.write('gamezID = fields[0].replace("[","").replace("]","").replace(" ","")') @@ -86,9 +89,11 @@ def GenerateSabPostProcessScript(): file.write("\n") file.write(" downloadStatus = 'Downloaded'") file.write("\n") - file.write('url = "' + gamezBaseUrl + 'updatestatus&game_id=" + gamezID + "&status=" + status') + file.write('url = "' + gamezBaseUrl + 'updatestatus?game_id=" + gamezID + "&status=" + downloadStatus') + file.write("\n") + file.write("print('Calling URL: ' + url)") file.write("\n") - file.write('responseObject = urllub.FancyURLopener({}).open(url)') + file.write('responseObject = urllib.FancyURLopener({}).open(url)') file.write("\n") file.write('responseObject.read()') file.write("\n") diff --git a/lib/DBFunctions.py b/lib/DBFunctions.py index fa7b6e6..e003ca2 100644 --- a/lib/DBFunctions.py +++ b/lib/DBFunctions.py @@ -105,7 +105,7 @@ def AddWiiGameToDb(db_id,status): def GetRequestedGames(): db_path = os.path.join(os.path.abspath(""),"Gamez.db") - sql = "SELECT wii_games.id,game_name,game_id,status FROM requested_games inner join wii_games on requested_games.WiiGameID = wii_games.ID" + sql = "SELECT wii_games.id,game_name,game_id,status FROM requested_games inner join wii_games on requested_games.WiiGameID = wii_games.ID order by game_name asc" data = '' connection = sqlite3.connect(db_path) cursor = connection.cursor() @@ -136,7 +136,7 @@ def RemoveWiiGameFromDb(db_id): def GetRequestedGamesAsArray(): db_path = os.path.join(os.path.abspath(""),"Gamez.db") - sql = "SELECT game_name,WiiGameID FROM requested_games inner join wii_games on requested_games.WiiGameID = wii_games.ID WHERE status='Wanted'" + sql = "SELECT game_name,WiiGameID FROM requested_games inner join wii_games on requested_games.WiiGameID = wii_games.ID WHERE status='Wanted' order by game_name asc" connection = sqlite3.connect(db_path) cursor = connection.cursor() cursor.execute(sql) diff --git a/lib/GameTasks.py b/lib/GameTasks.py index ed09055..cc91d8f 100644 --- a/lib/GameTasks.py +++ b/lib/GameTasks.py @@ -5,10 +5,12 @@ import os import shutil import stat +from subprocess import call class GameTasks(): def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort): + GameTasks().CheckIfPostProcessExistsInSab(sabnzbdApi,sabnzbdHost,sabnzbdPort) nzbmatrixusername = nzbmatrixusername.replace('"','') nzbmatrixapi = nzbmatrixapi.replace('"','') games = GetRequestedGamesAsArray() @@ -40,12 +42,12 @@ def FindGameOnNZBMatrix(self,game_name,game_id,username,api,sabnzbdApi,sabnzbdHo return def AddNZBToSab(self,nzbID,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id): - GameTasks().CheckIfPostProcessExistsInSab(sabnzbdApi,sabnzbdHost,sabnzbdPort) nzbUrl = "http://api.nzbmatrix.com/v1.1/download.php?id=" + nzbID url = "http://" + sabnzbdHost + ":" + sabnzbdPort + "/sabnzbd/api?mode=addurl&pp=3&apikey=" + sabnzbdApi + "&script=gamezPostProcess.py&name=" + nzbUrl + "&nzbname=[" + game_id + "] - "+ game_name responseObject = urllib.FancyURLopener({}).open(url) responseObject.read() responseObject.close() + return def CheckIfPostProcessExistsInSab(self,sabnzbdApi,sabnzbdHost,sabnzbdPort): path = os.path.abspath("postprocess") @@ -58,14 +60,13 @@ def CheckIfPostProcessExistsInSab(self,sabnzbdApi,sabnzbdHost,sabnzbdPort): scriptDir = response.split(":")[2].replace("'","").replace(" ","").replace("{","").replace("}","").replace("\n","") destPath = os.path.join(scriptDir,"gamezPostProcess.py") - if(os.path.isfile(destPath) == False): - try: - shutil.copyfile(srcPath,destPath) - except: - print 'Error Copying File' try: - if (os.access(destPath, os.R_OK) == False): - os.chmod(destPath,stat.S_IRWXO) + shutil.copyfile(srcPath,destPath) + except: + print 'Error Copying File' + try: + cmd = "chmod +x '" + destPath + "'" + os.system(cmd) except: print 'Error Setting Permissions' return