Last active
September 27, 2023 15:14
-
-
Save Specnr/327cc1b1f76878bca75e175c459937ab to your computer and use it in GitHub Desktop.
Generates text files that update every 30s and can be used in OBS as text sources
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
import os | |
import requests | |
import time | |
import math | |
from datetime import datetime | |
def ms_to_str(ms): | |
milliseconds = math.floor((ms % 1000) / 100) | |
seconds = math.floor((ms / 1000) % 60) | |
minutes = math.floor((ms / (1000 * 60)) % 60) | |
hours = math.floor((ms / (1000 * 60 * 60))) | |
if (milliseconds >= 5): | |
seconds = (seconds + 1) % 60 | |
if (seconds == 0): | |
minutes = (minutes + 1) % 60 | |
if (minutes == 0): | |
hours += 1 | |
# h = "0" + str(hours) if (hours < 10) else hours | |
m = "0" + str(minutes) if (minutes < 10) else minutes | |
s = "0" + str(seconds) if (seconds < 10) else seconds | |
ret = f"{m}:{s}" | |
return ret | |
def save_stat_to_file(name, to_save): | |
with open(f"{name}.txt", "w") as out_file: | |
out_file.write(str(to_save)) | |
sheet_id = "" | |
if os.path.exists("settings.txt"): | |
with open("settings.txt", "r") as settings: | |
sheet_id = settings.read().strip() | |
else: | |
sheet_id = input("Paste your sheet id in: ") | |
with open("settings.txt", "w") as settings: | |
settings.write(sheet_id) | |
while True: | |
try: | |
api = f"https://reset-analytics.vercel.app/api/sheet/{sheet_id}" | |
data = requests.get(api).json()["session"][0]["ops"] | |
except: | |
input("Failed to get data, make sure that the sheet id is correct, and that there's at least one session") | |
save_stat_to_file("Nethers-Per-Hour", round(data["fnph"], 2)) | |
save_stat_to_file("Blinds-Per-Hour", round(data["bph"], 2)) | |
save_stat_to_file("Reset-Count", data["rc"]) | |
sp = round(round(data["pc"] / data["rc"], 4) | |
* 100, 2) if data["rc"] > 0 else 0 | |
save_stat_to_file("Seeds-Played", f"{sp}%") | |
rpe = round(data["rc"] / data["tl"][2]["total"], | |
2) if data["tl"][2]["total"] > 0 else 0 | |
save_stat_to_file("Resets-Per-Enter", f"{rpe}") | |
ea = ms_to_str(data["tl"][2]["time"]) | |
save_stat_to_file("Nether-Enter-Average", f"{ea}") | |
curr_time = datetime.now().strftime("%H:%M:%S") | |
print(f"[{curr_time}] Stats Updated") | |
time.sleep(30) # Update once every 30s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
pip install requests
in cmd as a prerequisite