Skip to content

Instantly share code, notes, and snippets.

@DuncanRuns
Last active April 23, 2024 12:36
Show Gist options
  • Save DuncanRuns/3d74c0fb7a43e1284f0a1d1ba0474337 to your computer and use it in GitHub Desktop.
Save DuncanRuns/3d74c0fb7a43e1284f0a1d1ba0474337 to your computer and use it in GitHub Desktop.
Multi Attempts Counter Combiner
import os
import traceback
# Make sure to use either double backslash (\\) or single slashes (/)
directories = [
"C:\\MC Instances\\Speedrun 1.15\\.minecraft",
"C:\\MC Instances\\Speedrun 1.15 #2\\.minecraft",
]
# Either "ssgAttempts" or "rsgAttempts"
ATTEMPTS_KEY = "rsgAttempts"
class AttemptsInstance:
def __init__(self, directory: str) -> None:
self.path = os.path.join(directory, "config/atum/atum.properties")
self.last_m_time = 0
self.value = 0
def check(self) -> bool:
try:
if os.path.isfile(self.path):
new_m_time = os.path.getmtime(self.path)
if new_m_time == self.last_m_time:
return False
self.last_m_time = new_m_time
with open(self.path, "r") as a_file:
file_contents = a_file.read()
for line in [line.rstrip() for line in file_contents.splitlines()]:
if line.startswith(ATTEMPTS_KEY + "="):
self.value = int(line.split("=")[1])
return True
except Exception:
traceback.print_exc()
return False
def write(instances: list):
out = 0
for instance in instances:
out += instance.value
print("Writing attempts (" + str(out) + ") to totalattempts.txt.")
with open("totalattempts.txt", "w+") as ta_file:
ta_file.write(str(out))
ta_file.close()
if __name__ == "__main__":
import time
instances = [AttemptsInstance(i) for i in directories]
while True:
time.sleep(1)
update = False
for i in instances:
if i.check():
update = True
if update:
write(instances)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment