-
Notifications
You must be signed in to change notification settings - Fork 8
/
gamepoller.py
52 lines (42 loc) · 1.5 KB
/
gamepoller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import MySQLdb
import time
import os
import signal
import subprocess
db = MySQLdb.connect(host="dlw-hackathon.westeurope.cloudapp.azure.com", user="hackathon", passwd="Delaware.2011",
db="hackathon")
#create a cursor for the select
cur = db.cursor()
gameRunning = False
proc = "" #notreally
while True:
db = MySQLdb.connect(host="eu-cdbr-azure-west-b.cloudapp.net", user="b7f7d467f4d922", passwd="94f415a0",
db="dlwhackathon")
cur = db.cursor()
cur.execute("select id,status from dlwhackathon.game order by timestamp desc")
row = cur.fetchone()
print("gepolld:", str(row[0]), str(row[1]))
if int(row[1]) != 1:
print("Spel is niet bezig!")
if gameRunning:
gameRunning = False
#TODO actually stop the game, how?
#os.system("python theActualGame.py")
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
print("stopped game script")
else:
print("Spel is bezig!")
if not gameRunning:
gameRunning = True
# TODO actually start the game
os.system("echo " + str(row[0]) +" > currentGame.txt")
proc = subprocess.Popen(
"python theActualGame.py",
stderr=subprocess.STDOUT, # Merge stdout and stderr
stdout=subprocess.PIPE,
shell=True,
preexec_fn=os.setsid)
print("started game script")
cur.close()
db.close()
time.sleep(10)