March 26, 2020 Python Q&A

Topics covered in this session include:

  • Review of the Google authentication process
  • Writing Google sheets using df2gspread
  • Example of FinViz web scan data pushed into Google sheets

FinVizTest_df2gspread

# -*- coding: utf-8 -*-
"""
Created on Thu Mar 12 07:45:26 2020

@author: Bruce1
"""
#https://finviz.com/screener.ashx?v=111&f=ind_copper,sec_basicmaterials

#
#  This did not work, RunTime Error with Spyder IDE
#from finviz.screener import Screener

#filters = ['ind_copper', 'sec_basicmaterials']  # Shows companies in NASDAQ which are in the S&P500
# Get the first 50 results sorted by price ascending
#stock_list = Screener(filters=filters, order='price')

import pandas as pd

from df2gspread import df2gspread as d2g
from df2gspread import gspread2df as g2d

url = 'https://finviz.com/screener.ashx?v=111&f=ind_aluminum,sec_basicmaterials'

df = pd.read_html(url, header=0)[14]

print(df[['Ticker','Price']])

spreadsheet = '/new_folder/My_FinViz_Test'
wks_name = 'MAW1x'

d2g.upload(df, spreadsheet, wks_name)