# ========================================================================== # @author Paul Aurbano for BBT forums # @date 2021-02 # @description show FinViz news headers for a given array of tickers # @use this script is provided as it, no warranties provided # @license GPL # ========================================================================== import requests import sys import pandas as pd from tabulate import tabulate # double check arguments count args_count = int(format(len(sys.argv))) if args_count < 2: print("Pass any number of ticker symbol from the command line like:") print("X:>python finviznews.py TLRY AMD MU SNDL TSLA NIO") exit() # urls for connections base_url = "https://finviz.com/quote.ashx?t=" # basic initialization headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"} pd.options.display.width = 120 pd.options.display.max_colwidth = 100 for ticker in sys.argv[1:]: ticker = str(ticker).upper() url = base_url + ticker print() page = requests.get(url, headers=headers) df = pd.read_html(page.content, attrs={'class':'fullview-news-outer'} ) df = df[0] # df.set_index([0], inplace=True) print(tabulate(df.head(15), headers=['Date','News for '+str(ticker).upper()], tablefmt='simple', colalign=("right", "left"), showindex=False)) print()