-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticker_price.py
52 lines (42 loc) · 1.39 KB
/
sticker_price.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
import time
import sys
import Source.ComponentFactory as CF
import Source.Helper.Helper as Helper
import sys
MAX_NUMBER_OF_THREADS: int = 10
helper: Helper.helper = CF.ComponentFactory.getHelperObject()
if __name__ == "__main__":
processedSymbols: list[str] = []
stocks = sys.argv[1:]
startTime = time.time()
try:
if (len(stocks) == 0):
helper.retrieve_stock_list(stocks)
h_data, stocks = helper.download_historical_data(stocks)
except Exception as e:
raise Exception('Error: Could not build stock list - ', e)
if (len(stocks) % MAX_NUMBER_OF_THREADS == 0):
step = int(len(stocks)/MAX_NUMBER_OF_THREADS)
else:
step = int(len(stocks)/MAX_NUMBER_OF_THREADS) + 1
threads = []
stock_groups = []
for i in range(0, len(stocks), step):
stock_groups.append(stocks[i:i+step])
for i in range(len(stock_groups)):
threads.append(CF.ComponentFactory.getPriceCheckWorker(
i + 1,
"thread_" + str(i + 1),
i+1,
symbols=stock_groups[i],
h_data=h_data,
helper=helper
))
threads[int(i)].start()
for t in threads:
t.join()
del (threads)
end = time.time()
print("""Sticker Price Analysis Complete\n
Elapsed time: %2d minutes, %2d seconds\n"""
% ((end - startTime)/60, (end - startTime) % 60))