-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwritertest.py
35 lines (35 loc) · 1.29 KB
/
writertest.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
#!/usr/bin/python
import os
import faster_than_requests as requests
import json
import pathlib
import time
def downloadlogs(offset,interval):
response = requests.get("https://logs.tf/api/v1/log?offset=" + str(offset) + "&limit="+ str(interval))
responselist = json.loads(response.text)
logs = responselist.get("logs")
logslist = []
downloadedlogs = [s.replace(".json", "") for s in
os.listdir(path=r'/srv/http/tf2/Tf2LogSearcher/logs')]
for log in logs:
logslist.append(log.get("id"))
print(logslist)
for i in logslist:
if any(i == id for id in downloadedlogs):
break
else:
if not os.path.exists(r'/srv/http/tf2/Tf2LogSearcher/logs//'+str(i)+'.json'):
logdata = requests.get("http://logs.tf/json/" + str(i))
open(pathlib.Path(r'/srv/http/tf2/Tf2LogSearcher/logs/') / f"{i}.json",
'w').write(logdata.text)
print("[" + time.strftime("%Y/%m/%d %I:%M:%S %p") + "] Wrote " + str(i))
# 2000 requests seems to be the limit before logs.tf times you out
#i = 1111000
i = 0
while True:
try:
downloadlogs(i,10000)
except TimeoutError:
print("Timeout error caught: Restarting in 30 seconds")
time.sleep(30)
i = i + 10000