-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.py
More file actions
42 lines (35 loc) · 1.26 KB
/
common.py
File metadata and controls
42 lines (35 loc) · 1.26 KB
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
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from google.appengine.api import users
import urllib2, httplib, json
from time import sleep
redFont0 = '<font size=\"2\" color=\"red\">'
fontClose = '</font>'
def getResponse(url, opener = None):
good = False
while not good:
try:
resp = None
if not opener:
resp = urllib2.urlopen(url, timeout=60)
else:
resp = opener.open(url, timeout=60)
if resp.getcode() in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]:
good = True
except (urllib2.HTTPError, httplib.HTTPException):
pass
return resp.read()
def getResponseStub(url, opener):
r = json.loads(getResponse(url, opener))
cnt = 0
while (r['result'].lower()!='ok' and cnt < 5):
sleep(1)
cnt+=1
r = json.loads(getResponse(url, opener))
return r
def getCurrentGoogleUserCode():
user = users.get_current_user()
if not user:
return '<br>'*18+'<font color="red">Log in, with google account, no new registration needed!</font><a href="%s"> log in</a><br>' % users.create_login_url()
else:
return '<br>'*18+'<font color="red">Hello, %s, %s!</font><a href="%s"> log out</a>' % (user.nickname(), user.email(), users.create_logout_url('/'))