I have a python script that runs 24/7 and have a google spreadsheet that contains input values for the script. I update these values regularly. On a clean start, the initial value pulls in exactly as it should. The issue is when it needs to be updated. The new value on the spreadsheet isn't recognized unless the script is stopped and restarted.
Here is the code:
import gspread
import schedule
import time
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', scope)
gc = gspread.authorize(credentials)
sheet = gc.open('analyze_input')
wks = sheet.worksheet("Sheet1")
atr = wks.acell("A2").numeric_value
def atr_print():
print(atr)
schedule.every(60).seconds.do(atr_print)
while True:
schedule.run_pending()
time.sleep(1)
I've tried multiple variations of the code above - all with the same result. I was going to try the Cron scheduler / Cron tab next. Any ideas or suggestions would be a huge help, thanks!