Skip to content

Instantly share code, notes, and snippets.

@andr3w321
Last active February 22, 2021 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andr3w321/7a45903f5aaa3730fdfd9feb0d6f1af2 to your computer and use it in GitHub Desktop.
Save andr3w321/7a45903f5aaa3730fdfd9feb0d6f1af2 to your computer and use it in GitHub Desktop.
Download USA public companies' total assets numbers
from yahooquery import Ticker
import finvizlite as fl
import pandas as pd
def download_finviz_tickers(rows):
df = fl.scrape_all("https://finviz.com/screener.ashx?v=111&f=geo_usa&o=-marketcap", print_urls=True, rows=rows)
df.to_csv("finviz-tickers.csv", index=False)
def download_ticker_total_assets():
df = pd.read_csv("finviz-tickers.csv")
df.index = df['Ticker']
df['Total Assets latest'] = 0
df['Total Assets latest date'] = 0
df['Total Assets year ago'] = 0
df['Total Assets year ago date'] = 0
for ticker in df['Ticker']:
print(ticker)
t = Ticker(ticker)
df2 = t.balance_sheet(frequency='q')
if type(df2) != str:
df.loc[ticker,'Total Assets latest'] = df2["TotalAssets"][-1]
df.loc[ticker,'Total Assets latest date'] = df2["asOfDate"][-1]
df.loc[ticker,'Total Assets year ago'] = df2["TotalAssets"][0]
df.loc[ticker,'Total Assets year ago date'] = df2["asOfDate"][0]
df.to_csv("combined.csv")
download_finviz_tickers(500)
download_ticker_total_assets()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment