-
Notifications
You must be signed in to change notification settings - Fork 4
/
eventgroups.py
executable file
·60 lines (52 loc) · 3.08 KB
/
eventgroups.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
#!/usr/bin/python
#
# Silent Wings interface --- JSON formaat
#
import json
import time
from datetime import datetime
from datetime import timedelta
from datetime import date
import os
import config
localtime=datetime.now()
todaydate=localtime.strftime("%Y%m%d")
today=date.today()
evQ=[] # create the event entity
evL=[] # new instance of the event
ev2={'id':"LIVE"+todaydate, 'startOpenTs': int(time.time())}# Live today's event
evL.append(ev2) # add today's event
eventname=config.eventname1 # use the defaults
eventdesc=config.eventdesc1
cuc=os.listdir(config.cucFileLocation) # scan the cuc directory
for fn in cuc:
ft=fn[fn.find('.')+1:] # file type
fb=fn[0:fn.find('.')] # file base name
if (ft == 'cuc' or ft == 'json'): # only .cuc files
LQ=fn[0:4] # either LIVE or QSGP for the time being
y=int(fn[4:8]) # year
m=int(fn[8:10]) # month
d=int(fn[10:12]) # day
td=datetime(y,m,d)-datetime(1970,1,1) # number of second until beginning of the day
ts=td.total_seconds()+9*60*60 # timestamp 09:00:00 UTC
ex3={'id':fb , 'startOpenTs': int(ts)} # set the event ID and time for the start task
if (LQ == "LIVE"): # if LIVE event
evL.append(ex3) # add this event to the LIVE event group
else:
evQ.append(ex3) # add this event to the SGP event group
if LQ == config.Initials: # if is the same event
fname = config.cucFileLocation+fn
fd = open(fname, 'r') # read the JSON file generated by sgp2sws.py
j = json.loads(fd.read())
eventname=j['name'] # use the event name a description from the SGP website
eventdesc=j['description']
fd.close() # and close the file
# create the event groups
eg=[] # create the event group
eg1={'name':eventname, 'description': eventdesc, 'events': evQ, "bannerUrl": config.SWSserver+"SWS/SWSbanner.png"}
eg2={'name':config.eventname2, 'description': config.eventdesc2, 'events': evL, "bannerUrl": config.SWSserver+"SWS/SWSbanner.png"}
eg.append(eg1) # append the individual events groups
eg.append(eg2) # so far the QSGP and the LIVE
j=json.dumps(eg, indent=4) # convert it to JSON format
print (j) # pass it to the PHP script
exit()