The purpose of this program is to keep track of some stocks that we bought in a game and every week we must list the closing prices of each stock in a Google Sheet. I thought since I had a lot of different investments to keep track of I would write a quick script to do it for me. And I could have my friends in class send me their stocks as well to save them time.
I am just looking for any bad practices I might have in my code as well as any more efficient ways of carrying out some of the functions.
from yahoofinancials import YahooFinancials import re import pygsheets import pandas as pd import datetime now = datetime.datetime.now() time_now = (now.year, now.month, now.day) time_now = str(time_now) data =  formatedData =  shortData =  everything =  tickers = ['XOM', 'JNJ', 'TR', 'CRON', 'HSY', 'FL', 'PLNT', 'MCD', 'ARLP', 'LULU', 'RCII', 'DELL', 'DNKN', 'DIS'] def main(sheet, everything,place): gc = pygsheets.authorize(service_file='creds.json') # Create empty dataframe df = pd.DataFrame() # Create a column df['Closings: ' + time_now] = everything # open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet) sh = gc.open('PY to Gsheet Test') # select the first sheet wks = sh[sheet] # update the first sheet with df, starting at cell A2. wks.set_dataframe(df, (1, place)) # up/down,left right for i in tickers: tick = YahooFinancials(i) history = tick.get_historical_price_data('2019-03-07', '2019-03-08', 'daily') y = str(history) data.append(y) for i in data: i = i[i.index('adjclose'):] i = re.findall("\d+\.-?\d*", i) i = str(i) if len(i) > 7: formatedData.append(i[2:9]) #the decimals were really long so this shortens them down a bit else: formatedData.append(i) y = 0 for i in tickers: x = i x = x + " : " + formatedData[y] y = y + 1 everything.append(x) def get_name(person): if person == 'tommy': sheet = 0 elif person == 'chad': sheet = 1 elif person == 'kaya': sheet = 2 elif person == 'twohey': sheet = 3 elif person == 'majers': sheet = 4 elif person == 'tori': sheet = 5 elif person == 'kayla': sheet = 6 place = input("What Week Is This? 1,2,3,4,5?: ") # This will move the entry one place over for each week place = int(place) main(sheet, everything,place) print('DONT FORGET TO CHANGE TICKER') person = input("Whos Data Is Going In: ") get_name(person)