forked from SamPom100/StockClustering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.py
50 lines (42 loc) · 1.55 KB
/
driver.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
from database import *
from scraper import *
import queue
database = DataBase()
scraper = RobinScraper()
def main():
job_queue = queue.Queue()
job_queue.put('AAPL')
while True:
if job_queue.empty():
new_jobs = database.get_new_jobs()
if len(new_jobs) == 0:
break
for job in new_jobs:
job_queue.put(job)
ticker = job_queue.get()
print("Searching: ", ticker)
index = database.get_indexed_similar_tickers()
if ticker not in index:
tickerId = scraper.get_ticker_id(ticker)
similar_tickers = scraper.get_similar_tickers_populate(tickerId, database)
database.add_similar(ticker, similar_tickers)
print("Added: ", ticker)
else:
print("Seen: ", ticker)
def calc_sizes():
stock_dict = {}
for stock in database.get_indexed_similar_tickers():
for similar_stock in database.get_similar(stock):
if similar_stock not in stock_dict:
stock_dict[similar_stock] = 1
else:
stock_dict[similar_stock] += 1
for stock in stock_dict:
database.add_stock_count(stock, stock_dict[stock])
def add_straggler(ticker):
tickerId = scraper.get_ticker_id(ticker)
similar_tickers = scraper.get_similar_tickers_populate(tickerId, database)
tickerId2 = scraper.get_ticker_id(similar_tickers[0])
similar_tickers2 = scraper.get_similar_tickers_populate(tickerId2, database)
if __name__ == "__main__":
main()