2021-05-24 00:37:28 -05:00
|
|
|
import requests
|
2021-05-24 22:51:46 -05:00
|
|
|
import json
|
|
|
|
import time
|
2021-05-24 23:00:05 -05:00
|
|
|
|
2021-05-24 22:51:46 -05:00
|
|
|
from mastosnake import Mastosnake as mastosnake
|
|
|
|
from snake import Snake as snake
|
2021-05-24 23:00:05 -05:00
|
|
|
from config import token
|
|
|
|
from config import host
|
2021-05-24 22:51:46 -05:00
|
|
|
|
|
|
|
postend = 'api/v1/statuses'
|
|
|
|
getend = 'api/v1/polls/'
|
2021-05-24 00:37:28 -05:00
|
|
|
auth = {'Authorization': 'Bearer ' + token }
|
2021-05-24 22:51:46 -05:00
|
|
|
|
|
|
|
def main():
|
|
|
|
game = snake()
|
|
|
|
mastogame = mastosnake(game)
|
|
|
|
while True:
|
|
|
|
data = mastogame.returnStatus()
|
|
|
|
r = requests.post("https://" + host + postend, json=data, headers=auth)
|
|
|
|
print("posting game status")
|
|
|
|
|
|
|
|
if mastogame.game.gamestate == "gameover":
|
|
|
|
print("gameover")
|
|
|
|
time.sleep(10)
|
|
|
|
game = snake()
|
|
|
|
mastogame = mastosnake(game)
|
|
|
|
continue
|
|
|
|
|
|
|
|
time.sleep(120)
|
|
|
|
|
|
|
|
poll_id = json.loads(r.text)['poll']['id']
|
|
|
|
r = requests.get("https://" + host + getend + poll_id)
|
|
|
|
mastogame.updateState(json.loads(r.text))
|
|
|
|
print("game state has been updated")
|
|
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
print("posting new game status")
|
|
|
|
|
2021-05-24 23:00:05 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|