-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttpserver.py
53 lines (42 loc) · 1.92 KB
/
httpserver.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
from flask import Flask
class RESTful:
def __init__(self, interfaceObject):
self.program = interfaceObject
def run(self):
app = Flask(__name__)
@app.route('/register/<userName>/<password>')
def register(userName, password):
self.program.addUser(userName, password)
return "User registered successfully"
@app.route('/login/<userName>/<password>')
def login(userName, password):
if self.program.verifyUserLogin(userName, password):
return 0
else:
return 1
@app.route('/changeSensitivity/<userName>/<topicName>')
def changeSensitivity(userName, topicName, sensitivity):
if topicName in self.program.userList[userName].subList:
self.program.userChangeSensitivity(userName, topicName, sensitivity)
return 0
return 1
@app.route('/subscribe/<userName>/<topicName>/<sensitivity>')
def subscribe(userName, topicName, sensitivity):
if topicName in self.program.topicList:
if topicName not in self.program.userList[userName].subList:
self.program.userSubscribe(userName, topicName, sensitivity)
return 0
return 1
@app.route('/unsubscribe/<userName>/<topicName>')
def unsubscribe(userName, topicName):
if topicName in self.program.userList[userName].subList:
self.program.userUnsubscribe(userName, topicName)
return 0
return 1
@app.route('/getTopics/<userName>')
def getTopics(userName):
return self.program.getTopicsByUser(userName)
@app.route('/getMessages/<topicName>/<sensitivity>')
def getMessages(topicName, sensitivity):
return self.program.getMessagesByTopic(topicName, sensitivity)
app.run(debug=True)