Created
December 11, 2018 05:38
-
-
Save Scub3d/ebf4b4acb726ee9c89ac39adfcb52d49 to your computer and use it in GitHub Desktop.
Python code that gets and records the LoL Esports websocket data
This file contains 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
# -*- coding: utf-8 -*- | |
import websocket, thread, time, requests, json | |
from firebase import firebase | |
# I use firebase to store everything, but it can be adpated to work with other stuff | |
firebaseURL = '<your firebase database (not firestore) url here>' | |
firebase = firebase.FirebaseApplication(firebaseURL, authentication=None) | |
def getStreamToken(): | |
r = requests.get("http://api.lolesports.com/api/issueToken") | |
return r.json() | |
def on_message(ws, message): | |
msg = json.loads(message) | |
print "Message recieved" | |
if len(msg.keys()) == 1: | |
firebase.patch("livestream/" + str(msg.keys()[0]) + "/frames/" + str(msg[str(msg.keys()[0])]["t"]), msg[str(msg.keys()[0])]) | |
else: | |
for m in msg.keys(): | |
firebase.patch("livestream/" + str(m) + "/info", msg[str(m)]) | |
def on_error(ws, error): | |
print error | |
def on_close(ws): | |
print "### closed ###" | |
if __name__ == "__main__": | |
websocket.enableTrace(True) | |
ws = websocket.WebSocketApp("ws://livestats.proxy.lolesports.com/stats?jwt=" + getStreamToken()["token"], | |
on_message = on_message, | |
on_error = on_error, | |
on_close = on_close) | |
ws.run_forever() | |
# td = total dmg | |
# tdc = total dmg to champions | |
# tg = total gold | |
# trd = true dmg | |
# trdc = true dmg to champions | |
# x = ? (position?) | |
# xp = xp | |
# y = ? (position?) | |
# pd = physical dmg | |
# pdc = physical dmg to champions | |
# p = ? | |
# md = magic dmg | |
# mdc = magic dmg to champions | |
# h = ? current health? | |
# cg = current gold | |
# mk = minion kills | |
# items = current items. items[6] = trinket slot\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment