-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
52 lines (44 loc) · 1.79 KB
/
server.py
File metadata and controls
52 lines (44 loc) · 1.79 KB
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
import threading
from flask import Flask
from flask_restful import Resource, Api
from api.mm_api import *
from api.util import *
from threading import Thread
from time import sleep
import datetime
app = Flask(__name__) #create Flask instance
api = Api(app) #api router
api.add_resource(Login, '/login')
api.add_resource(Friends, '/friends')
api.add_resource(Playing, '/playing')
api.add_resource(Songs, '/songs')
api.add_resource(Location, '/location')
api.add_resource(FriendRequest, '/friends/requests')
api.add_resource(FriendDeny, '/friends/deny')
api.add_resource(FriendAccept, '/friends/accept')
api.add_resource(LocationsFollowed, '/locations/followed')
api.add_resource(LocationsFollow, '/locations/follow')
api.add_resource(LocationsUnfollow, '/locations/unfollow')
@app.after_request
def apply_caching(response):
response.headers["Access-Control-Allow-Origin"] = "*"
return response
# def song_checker():
# threading.Thread(target=exe).start()
#
# def exe():
# while(True):
# resp = exec_get_all("SElECT username,playTimeStamp from (LocationHistory JOIN Users on LocationHistory.username=Users.username) WHERE playTimeStamp < now() - interval '5 minutes'")
# for user in resp:
# exec_commit("UPDATE Users SET currentSongName=NULL, currentSongGenre=NULL, currentSongArtist=NULL,"
# "currentSongId=NULL,currentLat=NULL,currentLong=NULL WHERE username=%s", [user[0]])
# exec_commit("DELETE FROM LocationHistory WHERE username=%s AND playTimeStamp=%s", [user[0], user[1]])
# print(user[0] + " has been reset")
#
# sleep(300)
if __name__ == '__main__':
print("Starting flask")
print("Starting Database")
exec_sql_file('deploy.sql')
# song_checker()
app.run(debug=True,host='0.0.0.0') #starts Flask