-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_feeds.py
26 lines (24 loc) · 1 KB
/
fetch_feeds.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
import pandas as pd
import os
import yfinance as yf
data = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
table = data[0]
tickers = table['Symbol'].tolist()
FEEDS_DIR = './data_feeds/'
# todo validate data_feed directory
lost = []
for symbol in tickers:
try:
if not os.path.exists(f'{FEEDS_DIR}{symbol}.csv'):
print('downloading data feed of {}'.format(symbol))
symbol = symbol.replace('.','')
feed = yf.download(symbol, start=None, end=None, progress=True) # when start and end are None gives all histroy until today.
feed = feed[feed.columns[[1,2,0,3,5,4]]] # backward compatibility to the way the feed loader works
feed.to_csv(f'{FEEDS_DIR}{symbol}.csv')
else:
print('data feed of {} already exists, skipping'.format(symbol))
except Exception as e:
print(e)
lost.append(symbol)
if len(lost):
print("\033[31mError downloading {} symbols: {}.\033[00m".format(len(lost), lost))