-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
42 lines (28 loc) · 781 Bytes
/
server.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
from __future__ import unicode_literals
import asyncio
from ably import AblyRest
import web
from local_os import ABLY_API_KEY
# locally change to your ably API KAY
apiKey = ABLY_API_KEY
client = AblyRest(apiKey)
render = web.template.render('templates/')
class index:
def GET(self):
return render.index(apiKey)
class publish:
def GET(self):
return render.publish()
def POST(self):
message = web.input().get('message')
if message is not None:
channel = client.channels.get('sport')
asyncio.run(channel.publish('update', message))
raise web.seeother('/publish')
urls = (
'/', index,
'/publish', publish
)
app = web.application(urls, globals())
if __name__ == "__main__":
app.run()