-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordmcochat.py
37 lines (34 loc) · 1.02 KB
/
recordmcochat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import time
import html
def requestmorelog():
r = requests.get('https://minecraftonline.com/cgi-bin/tailminecraftlog.sh')
r2 = requests.utils.get_unicode_from_response(r)
return(r2)
def recordchat(text):
print(text)
f = open("log.txt", mode="a+")
f.write(text+"\n")
f.close()
return(None)
def mainloop(lastchunk):
starttime = time.time()
newchunk = requestmorelog()
newchunk = newchunk.replace("<br />", "")
newchunk = html.unescape(newchunk)
if newchunk != lastchunk:
print("")
currdate = time.strftime('%Y-%m-%d %H:%M:%S')
recordchat(f"[{currdate}] New chunk recieved:\n{newchunk}")
lastchunk = newchunk
else:
print(".", end=" ", flush=True)
if time.time() - starttime < 2:
time.sleep(2-(time.time() - starttime))
return(newchunk)
# we first initiate the log
currdate = time.strftime('%Y-%m-%d %H:%M:%S')
recordchat(f"[{currdate}] Starting logging")
lastchunk = ""
while True:
lastchunk = mainloop(lastchunk)