-
Notifications
You must be signed in to change notification settings - Fork 0
/
compilejson.py
68 lines (55 loc) · 1.83 KB
/
compilejson.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
import json
import os
def BuildFile(guildid):
filepath = "./data/{}.json".format(guildid)
with open(filepath, "r+") as jsonFile:
data = json.load(jsonFile)
datastring = "Agenda - {}/{}/{}.\n\n".\
format(data['day'], data['month'], data['year'])
counter = 0
runningstring = ""
for m in data['items']:
if m['urgent'] == 1:
counter = counter + 1
runningstring += "{username}: {content}.\n".\
format(content=m['content'], username=m['username'])
if counter > 0:
datastring += "URGENT:\n"
datastring += runningstring
counter = 0
runningstring = ""
for m in data['items']:
if m['urgent'] == 0:
counter = counter + 1
runningstring += "{username}: {content}.\n".\
format(content=m['content'], username=m['username'])
if counter > 0:
datastring += "\nMain:\n"
datastring += runningstring
counter = 0
runningstring = ""
for m in data['items']:
if m['urgent'] == -1:
counter = counter + 1
runningstring += "{username}: {content}.\n".\
format(content=m['content'], username=m['username'])
if counter > 0:
datastring += "\nLast on the Agenda:\n"
datastring += runningstring
datastring += "\nEND OF FILE\n"
return datastring
def ExportToFile(runningstring, guildid):
filepath = "./data/{}.txt".format(guildid)
file = open(filepath, "w")
file.write(runningstring)
file.close()
def MoveJSON(guildid):
src = "./data/{}.json".format(guildid)
dst = "./data/{}.old".format(guildid)
if os.path.isfile(dst):
os.remove(dst)
os.rename(src, dst)
def StartBuild(guildid):
runningstring = BuildFile(guildid)
ExportToFile(runningstring, guildid)
MoveJSON(guildid)