Skip to content

Instantly share code, notes, and snippets.

@Muffindrake
Created March 4, 2020 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muffindrake/afb67c7b90ebd5c7f5b8b3065624ebe6 to your computer and use it in GitHub Desktop.
Save Muffindrake/afb67c7b90ebd5c7f5b8b3065624ebe6 to your computer and use it in GitHub Desktop.
A tiny program to parse the LeagueClient log and open profiles on various statistics sites for players in lobbies
#!/usr/bin/env -S nim c --run -d:release
import browsers
import json
import os
import strformat
import strutils
import times
import uri
var logpath : string
var region : string
var user : string
proc lol_most_recent_log(path : string) : string =
var recent = from_unix(0)
for file in walk_files(path / "*LeagueClientUx.log"):
var tmp = file.get_creation_time
if tmp > recent:
recent = tmp
result = file
proc lol_match_json(line : string) : string =
var start : int
var tail : int
start = line.find("{")
tail = line.rfind("}")
if start == -1 or tail == -1:
return ""
result = line[start..tail]
proc lol_log_browse(display_name : string) =
let s = &"https://www.leagueofgraphs.com/summoner/{region}/{display_name.encode_url}"
echo "user: ", display_name, ", url: ", s
open_default_browser s
when is_main_module:
logpath = get_env("LOL_LOGDIR", "").string
if logpath == "":
echo "LOL_LOGDIR empty or not set"
quit()
if not logpath.exists_dir:
echo "path `", logpath, "` does not exist"
quit()
region = get_env("LOL_REGION", "").string
if region == "":
echo "LOL_REGION empty or not set"
quit()
user = get_env("LOL_USER", "").string
if user == "":
echo "LOL_USER empty or not set"
quit()
var logfile = lol_most_recent_log(logpath)
var newlog : string
var handle : File
var offset : int64
var user_info : seq[string]
while true:
newlog = lol_most_recent_log(logpath)
if newlog != logfile:
logfile = newlog
offset = 0
try:
handle = open(logfile)
except IOError as e:
echo "file `", logfile, "` could not be opened: ", e.msg
quit()
try:
handle.set_file_pos offset
except IOError:
echo "unable to seek to offset ", offset, " for a file of size ", handle.get_file_size
quit()
while true:
try:
for text in handle.lines:
var tmp = text.lol_match_json
if tmp == "":
continue
var j : JsonNode
try:
j = tmp.parse_json
except JsonParsingError as e:
echo "invalid json: ", e.msg
continue
var display_name = j{"displayName"}.get_str
if display_name == "" or display_name == user:
continue
user_info.add display_name
except IOError as e:
echo "reading from ", logfile, "caused: ", e.msg
quit()
if user_info.len != 0:
for user in user_info:
user.lol_log_browse
user_info.set_len 0
if handle.end_of_file:
offset = handle.get_file_pos
handle.close
sleep 15000
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment