You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
931 B

2 years ago
from mctools import PINGClient
2 years ago
ping = PINGClient('play.dmcraft.online')
2 years ago
#stats = ping.get_stats()
#Work with JSON
import json
def read():
global db
with open('db.json', 'r') as openfile:
db = json.load(openfile)
def write():
global db
js = json.dumps(db, indent=4)
with open("db.json", "w") as outfile:
outfile.write(js)
#My libraries
from time import sleep
#Read
read()
2 years ago
needsleep = 0
2 years ago
ttime = 0
2 years ago
while True:
2 years ago
if needsleep == 30:
needsleep = 0
sleep(30)
2 years ago
ttime = 29
2 years ago
else:
sleep(1)
needsleep += 1
2 years ago
2 years ago
try:
#if True:
stats = ping.get_stats()
if stats['players']['online'] != 0:
for i in stats['players']['sample']:
#Add in db if not in db
if i[0] not in db:
2 years ago
db[i[0]] = 1 + ttime
2 years ago
write()
else:
2 years ago
db[i[0]] = db[i[0]] + 1 + ttime
2 years ago
write()
2 years ago
ttime = 0
2 years ago
2 years ago
except Exception as e:
2 years ago
if e == '[Errno 32] Broken pipe':
sleep(60)
ttime = 59
print("CATCHED")
else:
print(e)
2 years ago