def scanServer( id ): #fetches charname and realm for the selected server via the auction api (getAllChars) and writes them in to the corresponding staging tabe print("Fetching Data for Server ID {}".format(id)) serverinfo = dbc.getServerbyID(id) if serverinfo[0] == "error": return serverinfo[1] if serverinfo[2] == True: return f"Server {serverinfo[0]} is set to \"Skip\"." server = serverinfo[0] server_realms = dbc.getConnectedRealms(id) print("Server {}, last scanned on: {}".format(serverinfo[0], serverinfo[1])) charlist_raw = bac.getAllChars(server, "eu") charlist = [(row[0], row[1]) for row in charlist_raw if row[0].lower() in server_realms] #for verbosity: print( f"{len(charlist_raw) - len(charlist)} entries don't match selected Server" ) if len(charlist_raw) - len(charlist) > 0: print([ chartuple for chartuple in charlist_raw if chartuple[0].lower() not in server_realms ]) print( dbc.writeCharNamesAtOnce("Server_" + server, charlist, verbosity=True, chunks=100)) print(dbc.updateServerScanbyID(id)) return "Server {} scanned successfully".format(server)
def GetBG2s(realm, char): dictTuple = bac.getBGs(char, realm, "eu") cardsdict = ir.refineBGInfo(dictTuple[1]) infodict = dictTuple[0] infodict = ir.refineCharInfo(infodict) chartfile = ir.createMoreBGCharts(infodict["name"], infodict["realm"], cardsdict) return render_template("bg.html", title="Character Selection", cardsdict=cardsdict, infodict=infodict, chartfile=chartfile)
def transferCharbyServerID( id, chunksize=100 ): #transfers a chunk of entries from a staging table to the main db. -> use bulkTransferCharbyServerId serverinfo = dbc.getServerbyID(id) if serverinfo[0] == "error": return serverinfo[1] if serverinfo[2] == True: return f"Server {serverinfo[0]} is set to \"Skip\"." print(f"Searching for untransferred Chars. Chunksize set to {chunksize}") server = serverinfo[0] charlist = dbc.getUntransferredChars("Server_" + server, chunksize=chunksize) if len(charlist) == 0: return "No untransferred Chars found" print(f"Found {len(charlist)} untransferred Chars") index = 1 for char in charlist: print(f"fetching Char Info {index}/{len(charlist)} -> {char[1]:12}", end="\r") index += 1 infodict = bac.getBGs(char[1], char[0], "eu")[0] if "status" in infodict: print("{}: {}".format(infodict["reason"], char[1]), end="\n") print("Removed Char from Table {}: {}".format( "Server_" + server, dbc.removeCharfromTable("Server_" + server, char))) else: infodict = ir.refineCharInfo(infodict) if dbc.transferChartogeneral(infodict["name"], infodict["realm"], id, infodict["class"], infodict["level"], infodict["faction"], infodict["race"]) == True: if dbc.setCharasTransferred("Server_" + server, char) == True: continue else: print( "Error while setting Char to transferred. Char removed from player_general: {}" .format(dbc.removeCharfromGeneral(char[1], char[0]))) print("") return "Done."
def scanfromGeneralbyServerID(id, lvl=120, chunksize=1000, days=7, fail_thresh=3): serverinfo = dbc.getServerbyID( id) #returns the name of the server from the serverlist if serverinfo[0] == "error": return (serverinfo[1], 0) print(f"Scanning Chars from player_general. Chunksize set to {chunksize}") server = serverinfo[0] charlist = dbc.getCharsfromGeneral(id, lvl, chunksize, days) if len(charlist) == 0: return ( f"No Chars found with Server_ID {id}, lvl {lvl}, that have not been scanned in the last {days} days and a fail threshold below {fail_thresh}", 0) charlist_updated, bgdictlist = bac.getBulkBgsforGeneral(charlist) print("Updating entries") errorcount = dbc.bulkUpdateCharsGeneral(charlist_updated) print(f"Updating complete with {errorcount} errors.") print("Writing BG Information into DB") bg_db = dbc.bulkWriteBG(bgdictlist) if bg_db == True: return ( f"Successfully updated {len(charlist)} Entries from player_general and added {len(bgdictlist)} Entries to player_bg", len(charlist)) else: print("Error while writing into player_bg") return ("Error!", 0) return True
def GetBGs(realm, char): return jsonify(bac.getBGs(char, realm, "eu")[1])
def GetPvP(realm, char): return jsonify(bac.getPvP(char, realm, "eu"))
def GetDeaths(realm, char): return jsonify(bac.getDeaths(char, realm, "eu"))
def GetKillingBlows(realm, char): return jsonify(bac.getKillingBlows(char, realm, "eu"))
def GetHonorableKills(realm, char): return jsonify(bac.getHonorableKills(char, realm, "eu"))
def GetMounts(realm, char): return jsonify(bac.getMounts(char, realm, "eu"))
def GetAudit(realm, char): return jsonify(bac.getAudit(char, realm, "eu"))
def GetStatistics(realm, char): return jsonify(bac.getStatistic(char, realm, "eu"))
def bulktransferCharbyServerID( id, chunksize=100, fail_thresh=1 ): # transfers a chunk of entries from a staging table into the main table. serverinfo = dbc.getServerbyID( id) #returns the name of the server from the serverlist if serverinfo[0] == "error": return (serverinfo[1], 0) if serverinfo[2] == True: return (f"Server {serverinfo[0]} is set to \"Skip\".", 0) print( f"Searching for untransferred Chars. Chunksize set to {chunksize}, Failed Attempts Threshold is set to {fail_thresh}" ) server = serverinfo[0] charlist = dbc.getUntransferredChars( "Server_" + server, chunksize=chunksize, fail_thresh=fail_thresh ) #fetches all untransferred chars from the staging table if len(charlist) == 0: return ("No untransferred Chars found", 0) print( f"Found {len(charlist)} untransferred Chars.. fetching Char Information:" ) resultlist = bac.getBulkBgs( charlist ) #fetches Char Information from the blizzard api for all chars fetched from the staging table goodlist, badlist = splitResultlist( resultlist ) #splits api responses into "good" and "bad" (charname mismatch, realm mismatch, server error, etc...) infodictlist = [] for infolist in goodlist: infodictlist.append( ir.refineCharInfo(infolist) ) #refines the char information for entries in the goodlist if len( infodictlist ) > 0: #writes all chars from the goodlist with their api results into the main table print("Transferring Char Information to DB...") if dbc.bulktransferChartoGeneral(infodictlist, id) == True: print( "Chunk written to player_general successfully. Written {} entries." .format(len(infodictlist)), end="\n\n") else: print("Error while writing to player_general.") return ("Error!", 0) if len( badlist ) > 0: #increses failed_attempts for the entries from the badlist in the staging table failcount = 0 print("Updating failed Attempts for bad API responses") for index, entry in enumerate(badlist): print("Updating entry {}/{}".format(index + 1, len(badlist)), end="") print("\r", end="") if dbc.increaseFailCount("Server_" + server, (entry[3], entry[2])) == True: failcount += 1 else: print( "Error while incresing failed attempts {} from Server_{}". format(entry[2], server)) print("\nUpdated failed Attempts for {} entries".format(failcount), end="\n\n") # if len(badlist) > 0: # delcount = 0 # print("Removing bad entries from Server_{}".format(server)) # for index, entry in enumerate(badlist): # print("Updating entry {}/{}".format(index+1, len(badlist)), end="") # print("\r", end="") # if dbc.removeCharfromTable("Server_"+server, (entry[3], entry[2])) == True: delcount += 1 # else: # print("Error while deleting {} from Server_{}".format(entry[2],server)) # print("\nDeleted {} entries".format(delcount), end="\n\n") print("\nMarking Chars as transferred in Server_{}".format(server)) transresult = bulkMarkAsTransferred( infodictlist, server ) #marks the successfully transferred chars (goodlist) as transferred in the staging table print(transresult[0]) return ( "Done. Written {} entries into player_general, updated {} and increased Failed Attempts on {} entries from Server_{}" .format(len(goodlist), transresult[1], len(badlist), server), len(charlist))