lichess-notify/notify.py

25 lines
641 B
Python
Raw Normal View History

2020-04-24 17:20:43 +02:00
#!/usr/bin/env python
import berserk, subprocess
# Change ACCESS TOKEN according to your need
2020-04-24 18:35:25 +02:00
ACCESS_TOKEN=""
2020-04-24 17:20:43 +02:00
# Notify using notify-send
def notify_send(summary, message):
subprocess.Popen(['notify-send', '-u', 'critical','-t', '99999999', summary, message])
return
# Fetch data and notify
session = berserk.TokenSession(ACCESS_TOKEN)
client = berserk.Client(session=session)
data=client.games.get_ongoing()
for game in data:
opponent=game["opponent"]["username"]
lastMove=game["lastMove"]
2020-04-24 17:24:57 +02:00
if game["isMyTurn"]:
2020-04-24 18:35:25 +02:00
notify_send("Lichess.org ("+opponent+")","It is your turn !\n Your opponent played "+lastMove)
2020-04-24 17:20:43 +02:00