Would love some feedback on how to improve my code. It might not be as readable as I'd like in places, but it currently works. Note that this code will be adapted to work on a different spreadsheet, so making this extensible would be amazing. Also, is there any reason to put this code into a class? I come from a scripting background, and OOP concepts are new to me.
This is the data that it looks at:
The code gets a row which it uses its index to turn FALSE to TRUE after it sends an email. The email isn't implemented yet, but will be soon. Any suggestions for if there's something other then smtplib on python would be appreciated, as I might want to just send the email without hooking up an account (like
import gspread import pprint from oauth2client.service_account import ServiceAccountCredentials def setup_connection(spreadsheet): scope = ['https://spreadsheets.google.com/feeds'] creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope) client = gspread.authorize(creds) worksheet = client.open(spreadsheet).sheet1 return worksheet def send_email(is_sent, is_passing): """ Takes in two parameters to determine if 1. the email is sent 2. did the quiz-taker pass? Returns true if the email was sent and false if not. Will probably need to be updated, too! """ if not is_sent: print("sending email...") if is_passing: print("you passed! congratulations :)") else: print("sorry, but you didn't pass yet! We'd really love to see you at the MakerSpace, so make sure to try again!") return True else: print("email already sent.") return False def main(): worksheet = setup_connection('CoMotion Quiz Test Automation') rows = worksheet.get_all_values() index = 0 for row in rows: index = index + 1 if (row == "FALSE"): is_passing = (float(row)/30 > 0.8) is_sent = False if (send_email(is_sent, is_passing)): worksheet.update_acell('E' + str(index), "TRUE") # Updates the cell to reflect true else: print("these are not the droids you\'re looking for...") main()