Advertisement
Guest User

Publish to PostGres

a guest
Apr 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. def main(args):
  2. # process commandline args
  3. processArgs(args)
  4.  
  5. # read config files
  6. loadGameKnowledge()
  7.  
  8. conn = psycopg2.connect(database='TestServer', user='testuser', password='r4inbows', host='jgabe037.ath.cx', port='5432')
  9. cur = conn.cursor()
  10.  
  11.  
  12. files = [f for f in listdir("C:/Users/liado_000/Documents/mwo-screenshot-analyzer/input") if isfile(join("C:/Users/liado_000/Documents/mwo-screenshot-analyzer/input", f))]
  13. files.sort()
  14. files.reverse()
  15. print(files)
  16. if len(files)%2 != 0:
  17. error("Odd number of files found: %d" % len(files))
  18. return
  19.  
  20. count = len(files)/2
  21.  
  22. while len(files) != 0:
  23. (result, mech, status, score, kills, assists, damage, cbills, xp, psr) = (None,)*10
  24. file2 = files.pop()
  25. file1 = files.pop()
  26. log(file1 + " " + file2)
  27.  
  28. match = re.search(CONFIG.fnpattern, file1)
  29. if not match:
  30. error("Screenshot filename pattern: No match")
  31. continue
  32. datetime = time.strptime(match.group(), CONFIG.dtformat)
  33.  
  34. file1 = "C:/Users/liado_000/Documents/mwo-screenshot-analyzer/input/" + file1
  35. file2 = "C:/Users/liado_000/Documents/mwo-screenshot-analyzer/input/" + file2
  36. id = time.strftime("%Y-%m-%d %H-%M-%S", datetime)
  37. filedate = time.strftime("%Y-%m-%d %H:%M:%S", datetime)
  38. with Image.open(file1) as img:
  39. # load resolution information
  40. debug(repr(img.size))
  41. loadResolutionInfo(img.size)
  42. img = preprocess(img, id, "team")
  43. (dist, map) = getmap(img, id, file1)
  44. debug("Found Map: \"%s\" with distance=%s" % (map, repr(dist)))
  45. (dist, mode) = getmode(img, id, file1)
  46. debug("Found Mode: \"%s\" with distance=%s" % (mode, repr(dist)))
  47. mytime = gettime(img, id, file1)
  48. (result, mech, status, score, kills, assists, damage) = getplayerdata(img, id, file1)
  49. with Image.open(file2) as img:
  50. psr = getpsr(img, id, file2)
  51. img = preprocess(img, id, "player")
  52. cbills = getcbills(img, id, file2)
  53. xp = getxp(img, id, file2)
  54.  
  55. debug("%s,%s,%s,%s,%s,%d,%d,%d,%d,%d,%d,%d,%s,%s" % (filedate, result, mech, map, mode, status, score, kills, assists, damage, xp, cbills, psr, mytime))
  56.  
  57. shutil.move(file1, "C:/Users/liado_000/Documents/mwo-screenshot-analyzer/processed")
  58. shutil.move(file2, "C:/Users/liado_000/Documents/mwo-screenshot-analyzer/processed")
  59.  
  60. with open("C:/Users/liado_000/Documents/mwo-screenshot-analyzer/data.csv", "a") as myfile:
  61. myfile.write("%s,%s,%s,%s,%s,%d,%d,%d,%d,%d,%d,%d,%s,%s\n" % (filedate, result, mech, map, mode, status, score, kills, assists, damage, xp, cbills, psr, mytime))
  62. cur.execute(
  63. """INSERT INTO mwotestdb (filedate, result, mech, map, mode, status, score, kills, assists, damage, xp, cbills, psr, mytime)
  64. VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);""",
  65. (filedate, result, mech, map, mode, status, score, kills, assists, damage, xp, cbills, psr, mytime))
  66.  
  67.  
  68. print
  69. conn.commit()
  70. # Close communication with the database
  71. cur.close()
  72. conn.close()
  73. log("Finished")
  74. return
  75.  
  76. if __name__ == "__main__":
  77. main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement