forked from rsammelson/new-timeclock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
46 lines (33 loc) · 1.53 KB
/
converter.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
import rapidjson
import datetime
import os
oldPath = "../oldData/"
def portUser(information):
oldFilename = userInfo[0].strip().replace(" ", "")
newFilename = userInfo[0].strip().lower().replace(" ", "_")
with open("times/" + newFilename + ".json", "w") as newFile:
if os.path.exists(oldPath + "times/" + oldFilename + ".txt"):
data = {}
data["teams"] = [i.strip() for i in information[3].split(",")]
# if information[3].strip() == "none":
# data["teams"] = ["Other"]
data["role"] = information[2].strip()
newFile.write(rapidjson.dumps(data) + "\n")
with open(oldPath + "times/" + oldFilename + ".txt") as oldFile:
for line in oldFile:
signIOData = line.split("|")
io = signIOData[0].strip()
if io == "@":
io = "o"
elif io == "!":
io = "i"
ioTime = datetime.datetime.strptime(signIOData[1].strip(), "%H:%M:%S %d.%m.%Y")
signData = {"type": io, "time": ioTime}
signDataJson = rapidjson.dumps(signData, datetime_mode=rapidjson.DM_ISO8601)
newFile.write(signDataJson)
newFile.write("\n")
if __name__ == "__main__":
with open(oldPath + "usernameFile.txt") as usernameFile:
for line in usernameFile:
userInfo = line.split("|")
portUser(userInfo)