forked from applepi-2067/PiScout-2016
-
Notifications
You must be signed in to change notification settings - Fork 6
/
upload.py
99 lines (94 loc) · 3.08 KB
/
upload.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import ast
import json
import os
import requests
import serverinfo
from event import CURRENT_EVENT
print("Attempting to upload matches...")
if os.path.isfile("queue.txt"):
try:
with open("queue.txt", "r") as file:
print("Uploading matches")
lines = file.readlines()
total = len(lines)
for num, line in enumerate(lines[:]):
print("Uploading match " + str(num + 1) + " of " + str(total))
requests.post(
serverinfo.SERVER + "/submit",
data={"event": CURRENT_EVENT, "data": line, "auth": serverinfo.AUTH},
)
lines.remove(line)
os.remove("queue.txt")
except:
print("Failed miserably. Are you connected to the internet?")
with open("queue.txt", "w") as file:
file.seek(0)
for line in lines:
file.write(line)
file.truncate()
raise
else:
print("The match queue doesn't exist.")
n = 0
if os.path.isfile("pitQueue.txt"):
try:
with open("pitQueue.txt", "r") as file:
print("Uploading pit entries")
for line in file:
requests.post(
serverinfo.server + "/submit",
data={
"event": CURRENT_EVENT,
"pitData": line,
"auth": serverinfo.AUTH,
},
)
print("Uploaded pit entry number " + str(n))
n += 1
os.remove("pitQueue.txt")
except:
print("Failed miserably. Are you connected to the internet?")
else:
print("The pit queue doesn't exist.")
n = 0
if os.path.isfile("editQueue.txt"):
try:
with open("editQueue.txt", "r") as file:
print("Uploading edits")
for line in file:
editData = ast.literal_eval(line)
editData['auth'] = serverinfo.AUTH
requests.post(
serverinfo.SERVER + "/edit",
data=editData,
)
print("Uploaded edit entry number " + str(n))
n += 1
os.remove("editQueue.txt")
except:
print("Failed miserably. Are you connected to the internet?")
else:
print("The edit queue doesn't exist.")
n = 0
if os.path.isfile("deleteQueue.txt"):
try:
with open("deleteQueue.txt", "r") as file:
print("Uploading deletes")
for line in file:
key = ast.literal_eval(line)
requests.post(
serverinfo.SERVER + "/delete",
data={
"key": key,
"auth": serverinfo.AUTH
},
)
print("Uploaded delete entry number " + str(n))
n += 1
os.remove("deleteQueue.txt")
except:
print("Failed miserably. Are you connected to the internet?")
else:
print("The delete queue doesn't exist.")
print("Finished.")
input("Press Enter to exit")