Skip to content

Commit

Permalink
Fixed code for v.0.0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dlesk committed Dec 23, 2011
1 parent a86dd8a commit f5c2c2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
11 changes: 8 additions & 3 deletions Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(" ","")')
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions lib/DBFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions lib/GameTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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

0 comments on commit f5c2c2a

Please sign in to comment.