From 2d7607e403d9fd431b1e8e0e4d52c5a5093ca2b1 Mon Sep 17 00:00:00 2001 From: Niceygy Date: Sat, 4 Nov 2023 16:38:03 +0000 Subject: [PATCH] init --- logParse.py | 5 +++++ main.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 logParse.py create mode 100644 main.py diff --git a/logParse.py b/logParse.py new file mode 100644 index 0000000..170ec9f --- /dev/null +++ b/logParse.py @@ -0,0 +1,5 @@ + + + +logs = load("C:/Users/nicey/Saved Games/Frontier Developments/Elite Dangerous") +getCMDR(logs) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..6bfa615 --- /dev/null +++ b/main.py @@ -0,0 +1,63 @@ +from discordrp import Presence +import time + +import os +import glob +import json + +def load(logDir): + print("Parsing log file") + log_files = glob.glob(os.path.join(logDir, '*.log')) + latest_file = max(log_files, key=os.path.getmtime) + print("opening log file " + str(latest_file)) + res = [] + with open(latest_file) as f: + for line in f: + line = line.strip() # Remove leading/trailing whitespace + if line: # Skip empty lines + try: + data = json.loads(line) + res.append(data) + except json.JSONDecodeError: + print(f"Skipping line: {line}") + return res + +def getCMDR(logs): + print("Parsing log data") + with open("messages.json") as m: + messages = json.load(m) + for log in logs: + if "event" in log: + #print(log["event"]) + try: + if log["event"] == "Commander": + cmdr_name = log.get("Name", "") + print(f"Found commander: {cmdr_name}") + except Exception: + print("No commander found") + return cmdr_name + +client_id = "1170388114498392095" # Replace this with your own client id + +with Presence(client_id) as presence: + print("Connected") + cmdr = getCMDR(load("C:/Users/Nicey/Saved Games/Frontier Developments/Elite Dangerous")) + presence.set( + { + "state": "Playing as CMDR " + cmdr, + "details": "Playing Elite: Dangerous", + "timestamps": { + "start": int(time.time()), + }, + "assets": { + "large_image": "ed_main", # Replace this with the key of one of your assets + + }, + + + } + ) + print("Presence updated") + + while True: + time.sleep(15) \ No newline at end of file