-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (41 loc) · 1.15 KB
/
main.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
from src.api.lichess import Lichess
from src.chess.engine import ChessEngine
from src.db.db import DB
from datetime import datetime
import time
import sys
token = sys.argv[1]
engine = ChessEngine()
lichess = Lichess(token)
def game():
while True:
try:
stream = lichess.watchStream()
print(stream)
if stream['type'] == 'challenge':
challengeId = lichess.acceptChallenge(stream['challenge']['id'])
if challengeId.status_code == 200:
print(f'[{datetime.now().strftime("%H:%M:%S")}]: Challenge accepted!')
else:
print(challengeId)
if stream['type'] == 'gameStart':
print(f'[{datetime.now().strftime("%H:%M:%S")}]: Game started!')
checker=True
while checker:
gameId, fen, isMyTurn, color = lichess.streamGame()
move = engine.getMove(fen, color)
lichess.makeMove(gameId, isMyTurn, move)
if stream['type'] == "gameFinish":
checker=False
except:
pass
def seek():
while True:
try:
lichess.createSeek()
time.sleep(60*7.5)
except Exception as e:
print(e)
import threading
threading.Thread(target=game).start()
threading.Thread(target=seek).start()