forked from thinker3197/ChatBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackmsit.py
72 lines (55 loc) · 2.25 KB
/
hackmsit.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
from flask import Flask, render_template, request,session,redirect,url_for
from flask.ext.socketio import SocketIO,emit,join_room,leave_room
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.route('/',methods=['GET','POST'])
def index():
#webbrowser.open_new(url)
if request.method=='POST':
session['name'] = request.form['name']
session['room'] = request.form['room']
return redirect(url_for('py'))
return render_template('index.html',template_folder='templates')
@app.route('/py')
def py():
name = session.get('name','')
room = session.get('room','')
return render_template('out.html', name=name, room=room, template_folder='templates')
@socketio.on('connect',namespace='/chat')
def ws_connect():
"""Sent by clients when they enter a room.
A status message is broadcast to all people in the room."""
socketio.emit('msg',{'count':'0'},namespace='/chat',broadcast=True)
def check(link):
if link[0:4] == 'http':
return '<a target="_blank" href='+link+'>'+link+'</a>'
elif link[0:3] == 'www' :
return '<a target="_blank "href=https://'+link[4:] +'>'+link+'</a>'
else:
return link
@socketio.on('joined', namespace='/chat')
def joined(message):
"""Sent by clients when they enter a room.
A status message is broadcast to all people in the room."""
room = session.get('room')
join_room(room)
print "joined"
emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room,namespace='/chat')
@socketio.on('disp', namespace='/chat')
def ws_city(message):
print message['disp']
print "jouned new"
fina = check(message['disp'])
room = session.get('room')
print room
emit('disp', {'nam': session.get('name')+': ','disp' :fina},room = room,namespace='/chat')
@socketio.on("type",namespace='/chat')
def auto_print(message):
room = session.get('room')
print ">>>>>>>>>>>>>>>>>>>>>>"+str(room)
emit("atype",{'name':session.get('name')+" is typing ....",'press':message['press']},room=room,namespace='/chat')
if __name__ == '__main__' :
#port = int(os.environ.get('PORT', 5000))
socketio.run(app,host='0.0.0.0',port=5000,debug=True)
#app.run(debug=True)