-
Notifications
You must be signed in to change notification settings - Fork 0
/
.goutputstream-1LOGGW
72 lines (58 loc) · 2.02 KB
/
.goutputstream-1LOGGW
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
69
70
71
import os
from twisted.application import service, internet
from twisted.web import static, server
import cyclone.web
import cyclone.httpserver
try:
_port = int(os.environ["PORT"])
except:
_port = 80
class RedirectHandler(cyclone.web.RequestHandler):
def initialize(self, url):
self.url = url
def get(self):
self.redirect(self.url)
class OpenTemplateHandler(cyclone.web.RequestHandler):
def get(self, path):
print path
self.render(path+'.html')
class JsonpHandler(cyclone.web.RequestHandler):
'''Usage: /jsonp?word=ninja'''
def get(self):
word = self.get_argument('word')
wiki_query = 'http://en.wikipedia.org/w/api.php?action=parse&page='+word+'&prop=text|links&format=json&callback=parseWikiJson'
result = '''
<html>
<head>
<script type="text/javascript">
function parseWikiJson(data){
console.log(data);
console.log(data.parse.text['*'].length);
}
</script>
<script type="text/javascript" src="'''+wiki_query+'''"></script>
</head>
<body></body>
</html>'''
# '<script type="text/javascript" src="http://server2.example.com/RetrieveUser?UserId=1234&jsonp=parseResponse"></script>'
self.write(result)
class Application(cyclone.web.Application):
def __init__(self):
handlers = [
(r"/", RedirectHandler, {'url':'/#set-up'}),
(r"/jsonp/?", JsonpHandler),
(r"/(.*?)/?", OpenTemplateHandler),
]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "html"),
static_path=os.path.join(os.path.dirname(__file__), "html"),
debug=True,
autoescape=None,
# login_url="/sign-in",
cookie_secret="lRkzXk/nSmiAw/r0ZVrPAv5Di/Cr1Udep7TRY/pi56w=",
)
cyclone.web.Application.__init__(self, handlers, **settings)
# self.db = MongoDatabase()
site = Application()
application = service.Application("Depictionary")
internet.TCPServer(_port, site).setServiceParent(application)