Created
November 7, 2017 07:08
-
-
Save koma5/438dbf437701ef8e17dd8f9b9c969504 to your computer and use it in GitHub Desktop.
stealthy nofifications when I have to move next in my current lichess.org games.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import requests, json, os\n", | |
"\n", | |
"my_username = \"koma5\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n", | |
" InsecureRequestWarning)\n" | |
] | |
} | |
], | |
"source": [ | |
"# ignore the proxies=proxy, verify=False parameters if you do not sit behind an evil firewall which breaks ssl\n", | |
"# and needs you to authenticate. If your interested 127.0.0.1:3128 is CNTLM on windows\n", | |
"# so I don't have to write my password in plaintext into code\n", | |
"proxy = {\"https\" : 'http://127.0.0.1:3128'}\n", | |
"resp = requests.get('https://lichess.org/api/user/koma5/games?playing=1', proxies=proxy, verify=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"currentPage\": 1,\n", | |
" \"maxPerPage\": 10,\n", | |
" \"currentPageResults\": [\n", | |
" {\n", | |
" \"id\": \"kBH2iFjF\",\n", | |
" \"initialFen\": \"rqnknrbb/pppppppp/8/8/8/8/PPPPPPPP/RQNKNRBB w KQkq - 0 1\",\n", | |
" \"rated\": false,\n", | |
" \"variant\": \"chess960\",\n", | |
" \"speed\": \"correspondence\",\n", | |
" \"perf\": \"chess960\",\n", | |
" \"createdAt\": 1509008666117,\n", | |
" \"lastMoveAt\": 1510035428652,\n", | |
" \"turns\": 13,\n", | |
" \"color\": \"black\",\n", | |
" \"status\": \"started\",\n", | |
" \"players\": {\n", | |
" \"white\": {\n", | |
" \"userId\": \"koma5\",\n", | |
" \"name\": null,\n", | |
" \"rating\": 1500,\n", | |
" \"ratingDiff\": null,\n", | |
" \"provisional\": true\n", | |
" },\n", | |
" \"black\": {\n", | |
" \"userId\": \"cefazi\",\n", | |
" \"name\": null,\n", | |
" \"rating\": 1500,\n", | |
" \"ratingDiff\": null,\n", | |
" \"provisional\": true\n", | |
" }\n", | |
" },\n", | |
" \"url\": \"https://lichess.org/kBH2iFjF/white\"\n", | |
" }\n", | |
" ],\n", | |
" \"nbResults\": 1,\n", | |
" \"previousPage\": null,\n", | |
" \"nextPage\": null,\n", | |
" \"nbPages\": 1\n", | |
"}\n" | |
] | |
} | |
], | |
"source": [ | |
"plays = json.loads(resp.text)\n", | |
"print(json.dumps(plays, indent=2))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def notify(text):\n", | |
" # do whateber you want here. My sorry ass has a windows 10 client at work\n", | |
" # and useses SnoreToast for stealthy chess notifications\n", | |
" print(\"notified with: {}\".format(text) )\n", | |
" os.system(\"SnoreToast.exe -w -t \\\"ACTION\\\" -m \\\"{}.\\\" -appID \\\"My.APP_ID\\\"\".format(text)) " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"for play in plays['currentPageResults']:\n", | |
" my_color = \"white\" if play['players']['white']['userId'] == my_username else \"black\"\n", | |
" # is it me who has to move next?\n", | |
" if my_color == play['color']:\n", | |
" # some nice friendly and OPS emergency looking message, which only I understand.\n", | |
" notify('the waiting process with the pid {} has expired.'.format(play['id']))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment