Skip to content

Commit 0e6c80e

Browse files
Add infinite runtime to the client
1 parent 88363cd commit 0e6c80e

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

nuclearesrpc.py

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,41 @@ def find_nucleares():
7777
presence.connect()
7878
print("Connected. Press Ctrl+C to Exit")
7979
while 1:
80-
dvars = get_all_vars(url)
81-
if dvars["CORE_TEMP"] <= 50:
82-
details = "Reactor Offline"
83-
else:
84-
details = f"Reactor Online: {round(dvars['CORE_TEMP'])}C"
85-
pwr = dvars["GENERATOR_0_KW"] + dvars["GENERATOR_1_KW"] + dvars["GENERATOR_2_KW"]
86-
if pwr > 0:
87-
status = f"Producing {pwr} kW"
88-
else:
89-
status = "Generator Offline"
90-
if dvars["CORE_IMMINENT_FUSION"] == "TRUE":
91-
details = "Imminent Meltdown"
92-
presence.update(
93-
pid=proc.pid,
94-
start=round(starttime),
95-
details=details,
96-
state=status,
97-
)
98-
#print(
99-
# f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}"
100-
#)
101-
time.sleep(15)
80+
try:
81+
dvars = get_all_vars(url)
82+
if dvars["CORE_TEMP"] <= 50:
83+
details = "Reactor Offline"
84+
else:
85+
details = f"Reactor Online: {round(dvars['CORE_TEMP'])}C"
86+
pwr = round(dvars["GENERATOR_0_KW"] + dvars["GENERATOR_1_KW"] + dvars["GENERATOR_2_KW"])
87+
if pwr > 0:
88+
status = f"Producing {pwr} kW"
89+
else:
90+
status = "Generator Offline"
91+
if dvars["CORE_IMMINENT_FUSION"] == "TRUE":
92+
details = "Imminent Meltdown"
93+
presence.update(
94+
pid=proc.pid,
95+
start=round(starttime),
96+
details=details,
97+
state=status,
98+
large_image="nucleares"
99+
)
100+
#print(
101+
# f"Sent Update: Core = {dvars['CORE_TEMP']} - Total Pwr = {pwr} - Panic = {dvars['CORE_IMMINENT_FUSION']}"
102+
#)
103+
time.sleep(15)
104+
except requests.ConnectionError:
105+
print("Webserver connection lost, trying to re-establish...")
106+
if find_nucleares() is None:
107+
print("Nucleares is closed, RPC will close...")
108+
exit(0)
109+
while 1:
110+
try:
111+
# Try to query data until it succeeds
112+
requests.get(url, {"Variable": "CORE_TEMP"})
113+
break
114+
except requests.ConnectionError as e:
115+
time.sleep(5)
116+
print("Connected!")
117+
continue

0 commit comments

Comments
 (0)