-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
85 lines (73 loc) · 2.54 KB
/
server.py
File metadata and controls
85 lines (73 loc) · 2.54 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import schedule, time, json, sys
from datetime import datetime, timedelta
from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask_jsonpify import jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
from modules.scraper.scrape import *
from controller import Controller
#from tweetfilter import TweetFilter
#filter = TweetFilter()
controller = Controller()
app = Flask(__name__)
api = Api(app)
def periodic(scheduler, interval, action, actionargs=()):
scheduler.enter(interval, 1, periodic,
(scheduler, interval, action, actionargs))
action(*actionargs)
def job():
print("Streaming tweets started")
sinceScrape = (datetime.now()+timedelta(days=-1)).strftime('%Y-%m-%d')
untilScrape = datetime.now().strftime('%Y-%m-%d')
scrape(sinceScrape, untilScrape)
print("Streaming tweets ended")
print("Filtering tweets started")
filter.readTweets()
print("Filtering tweets ended")
def streamer():
schedule.every().day.at("08:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
def server():
@app.route('/getpolarities')
@cross_origin()
def get_polarities():
censustract = request.args.get('censustract')
since = request.args.get('since')
until = request.args.get('until')
return json.dumps(controller.getPolarities(censustract,since,until))
@app.route('/getcensusdata')
@cross_origin()
def get_censusdata():
since = request.args.get('since')
until = request.args.get('until')
mintime = request.args.get('mintime')
maxtime = request.args.get('maxtime')
aspecttype = int(request.args.get('aspecttype'))
return json.dumps(controller.getCensusdata(since,until,mintime,maxtime,aspecttype))
@app.route('/getdensitymaps')
@cross_origin()
def get_densitymaps():
since = request.args.get('since')
until = request.args.get('until')
mintime = request.args.get('mintime')
maxtime = request.args.get('maxtime')
return json.dumps(controller.getDensityMaps(since,until,mintime,maxtime))
app.run(port='8000')
if __name__ == '__main__':
#job()
#filter.readTweets()
server()
# try:
# _thread.start_new_thread(streamer, ())
# _thread.start_new_thread(server, ())
# except:
# print ("Error: unable to start thread")
# while 1:
# pass