-
Notifications
You must be signed in to change notification settings - Fork 3
/
yfinance-basic.py
51 lines (41 loc) · 1.38 KB
/
yfinance-basic.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
import yfinance as yf
import sys, logging, traceback
from dotenv import load_dotenv
import requests_cache
session = requests_cache.CachedSession('yfinance.cache')
session.headers['User-agent'] = 'my-program/1.0'
load_dotenv()
te = open("yfinance-dcf-output.txt", "a") # File where I keep the logs
class Unbuffered:
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
te.write(data) # Write the data of stdout here to a text file as well
def flush(self):
pass
sys.stdout = Unbuffered(sys.stdout)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Upendra: Enter your list of symbols here
mySymbols = ['GOOG']
"""
msft = yf.Ticker("MSFT")
# get stock info
msft.info """
def upendra_simple_dcf(ticker):
ticker_data = yf.Ticker(ticker, session=session)
""" for k, v in ticker_data.financials.items():
print(k, v) """
print(ticker_data.financials.get('Income Before Tax'))
for i in range(0, len(mySymbols)):
try:
print("%d. %s Yearly:" % (i, mySymbols[i]))
upendra_simple_dcf(mySymbols[i])
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print(message)
traceback.print_exc()
continue