Skip to content

Commit 058c637

Browse files
committed
yank CGI logic in postJson into a method
1 parent dfcf8ad commit 058c637

1 file changed

Lines changed: 34 additions & 29 deletions

File tree

‎example/postJson.py‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,39 @@
88
import fbsettings
99
from fogbugz import FogBugz
1010

11-
fb = FogBugz(fbsettings.URL, fbsettings.TOKEN)
12-
resp = fb.search(q='project:inbox area:* status:active due:today orderby:due',
13-
cols="dtDue,sTitle,sStatus")
14-
15-
myList = []
16-
17-
for case in resp.cases:
18-
date = datetime.strptime(case.dtdue.string, '%Y-%m-%dT%H:%M:%SZ').strftime('%m/%d/%Y')
19-
time = case.dtdue.string[11:16]
20-
departure = case.stitle.string.encode('UTF-8').replace('\"', '')
21-
if (datetime.strptime(case.dtdue.string, '%Y-%m-%dT%H:%M:%SZ') - datetime.now()).days < 0:
22-
status = 3
23-
else:
24-
status = 2
25-
track = random.randrange(0, 100)
26-
myList.append({'sDate': date,
27-
'sTime': time,
28-
'sDeparture': departure,
29-
'nStatus': 2,
30-
'nTrack': track,
31-
'bLight': False})
11+
12+
def cgi():
13+
fb = FogBugz(fbsettings.URL, fbsettings.TOKEN)
14+
resp = fb.search(q='project:inbox area:* status:active due:today orderby:due',
15+
cols="dtDue,sTitle,sStatus")
16+
17+
myList = []
18+
19+
for case in resp.cases:
20+
date = datetime.strptime(case.dtdue.string, '%Y-%m-%dT%H:%M:%SZ').strftime('%m/%d/%Y')
21+
time = case.dtdue.string[11:16]
22+
departure = case.stitle.string.encode('UTF-8').replace('\"', '')
23+
if (datetime.strptime(case.dtdue.string, '%Y-%m-%dT%H:%M:%SZ') - datetime.now()).days < 0:
24+
status = 3
25+
else:
26+
status = 2
27+
track = random.randrange(0, 100)
28+
myList.append({'sDate': date,
29+
'sTime': time,
30+
'sDeparture': departure,
31+
'nStatus': 2,
32+
'nTrack': track,
33+
'bLight': False})
3234

3335
#turn on the top light
34-
try:
35-
myList[0]['bLight'] = True
36-
except:
37-
pass
38-
39-
print "Content-Type: application/json"
40-
print
41-
print json.dumps(myList)
36+
try:
37+
myList[0]['bLight'] = True
38+
except:
39+
pass
40+
41+
print "Content-Type: application/json"
42+
print
43+
print json.dumps(myList)
44+
45+
if __name__ == '__main__':
46+
cgi()

0 commit comments

Comments
 (0)