-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (60 loc) · 2.04 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
""" main.py is the top level script.
Return "Hello World" at the root URL.
"""
from flask import Flask, request
from flask import render_template
import urllib2
import json
import random
import uuid
from google.appengine.api import users
from google.appengine.api import channel
from utilities import funnames
import os
import webapp2
import sys
# sys.path includes 'server/lib' due to appengine_config.py
app = Flask(__name__.split('.')[0])
@app.route('/')
@app.route('/')
def memory(name=None):
""" Return me template at application /me URL."""
return render_template('headerpg.html', name=name)
@app.route('/')
def index():
"""Setup a chat"""
roomid = generate_id()
template_values = {
"roomid":roomid
}
return render_template("index.html",values=template_values)
@app.route('/<roomid>/<name>')
def chatroom_and_name(roomid,name):
"""Return a chat page"""
token = channel.create_channel(name + roomid)
template_values = {
"roomid":roomid,
"token": channel.create_channel(name + roomid),
"yourname": name
}
return render_template("chat.html",values=template_values)
@app.route('/<roomid>')
def chatroom(roomid):
"""Return a chat page prompt for name
then redirect to chatroom_and_name"""
template_values = {
"roomid":roomid,
}
return render_template("getname.html",values=template_values)
@app.route('/sendmessage/<user>/<roomid>', methods=['GET', 'POST'])
def sendmessage(user,roomid):
"""sends a message that is useless"""
message = request.form['message']
channel.send_message(user+roomid,message)
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, No Valid Chatroom There.', 404
def generate_id():
"""Return a game id"""
return "%s-%s" % (str(uuid.uuid4())[:4],random.choice(funnames).lower())