/
StockAnalysisServer.py
53 lines (35 loc) · 1.2 KB
/
StockAnalysisServer.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
#this will be our main controller, it will start all process and handle user request
from flask import Flask
import DataStructure
import DataCollection
from threading import Thread
import QueryFunctions
#initialize data structure to store stock quotes
dataStruct = DataStructure.DataStructure()
#initialize the data structure
dataStruct.structInit(dataStruct)
#initializa the thread to collect data from yahoo api
dataCollectionObj =DataCollection.DataCollection()
thread = Thread(target = dataCollectionObj.producerFunctions, args= [dataStruct])
thread.start()
#thread.join()
app = Flask(__name__)
#access the dataStructure like this
#print dataStruct.stockHash
#functions for thread can be used in similar fashion
#our flask structure remains the same
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/query1/')
def index():
consumer=QueryFunctions.queries()
consumerThread = Thread(target = consumer.query1,args=[dataStruct])
consumerThread.start()
consumerThread.join()
consumerThread2 = Thread(target = consumer.query2,args=('goog',dataStruct,10,))
consumerThread2.start()
consumerThread2.join()
return 1;
if __name__ == '__main__':
app.run()