コード例 #1
0
def checkServerBest(conn, spawnID, spawnName, galaxy):
	result = serverBest.checkSpawn(spawnID)
	for x in range(len(result[1])):
		schematicStr = ''
		bestStr = ''
		for k, v in result[1][x].iteritems():
			quoteSchem = "".join(("'", k, "'"))
			schematicStr = ','.join((schematicStr, quoteSchem))
			bestStr = '\n'.join((bestStr, '\n'.join(v)))
		if schematicStr > 0:
			schematicStr = schematicStr[1:]
		# open people with favorites for the professions involved
		cursor = conn.cursor()
		cursor.execute("SELECT tFavorites.userID, defaultAlertTypes, profName FROM tFavorites INNER JOIN tUsers ON tFavorites.userID = tUsers.userID INNER JOIN tProfession ON tFavorites.itemID = tProfession.profID WHERE galaxy={1} AND favType=3 AND itemID={0} GROUP BY tFavorites.userID, defaultAlertTypes, profName;".format(result[0][x], galaxy))
		row = cursor.fetchone()
		# Add alert for each user watching for profession server bests hit by this spawn
		while row != None:
			addAlert(row[0], row[1], bestStr, ''.join(('http://galaxyharvester.net/resource.py/', str(galaxy), '/', spawnName)), ''.join((row[2], ' Server Best Alert')))
			row = cursor.fetchone()

		cursor.close()

		# open people with favorites for the schematics involved
		cursor = conn.cursor()
		cursor.execute("SELECT tFavorites.userID, defaultAlertTypes, schematicID, schematicName FROM tFavorites INNER JOIN tUsers ON tFavorites.userID = tUsers.userID INNER JOIN tSchematic ON tFavorites.favGroup = tSchematic.schematicID WHERE galaxy={1} AND favType=4 AND favGroup IN ({0}) GROUP BY tFavorites.userID, defaultAlertTypes, schematicID, schematicName;".format(schematicStr, galaxy))
		row = cursor.fetchone()
		# Add alert for each user watching for schematic server bests hit by this spawn
		while row != None:
			addAlert(row[0], row[1], '\n'.join(result[1][x][row[2]]), ''.join(('http://galaxyharvester.net/resource.py/', str(galaxy), '/', spawnName)), ''.join((row[3], ' Server Best Alert')))
			row = cursor.fetchone()

		cursor.close()
コード例 #2
0
def refreshServerBestStatus(spawnID):
    # Calculate new current Server Best info for spawn only if it has not been calculated within last 2 hours
    result = ''
    sqlStr = 'SELECT eventTime FROM tServerBestStatus WHERE spawnID={0};'.format(spawnID)
    checkCursor = conn.cursor()
    checkCursor.execute(sqlStr)
    checkRow = checkCursor.fetchone()
    checkCursor.close()
    if checkRow != None:
        timeAgo = datetime.fromtimestamp(time.time()) - checkRow[0]
        hoursAgo = timeAgo.seconds / 3600
        if hoursAgo > 1:
            cleanCursor = conn.cursor()
            cleanCursor.execute('DELETE FROM tServerBestStatus WHERE spawnID=%s;', [spawnID])
            cleanCursor.close()
            result = serverBest.checkSpawn(spawnID, 'current')
        else:
            result = 'Current best use info was calculated for this resource {0} minutes ago, so displaying those results below.  Current best calculations cannot be run more than every 2 hours.\n'.format(str(timeAgo.seconds/60))
    else:
        result = serverBest.checkSpawn(spawnID, 'current')
    return result