我有一个将自动运行的代码,我需要保存上次运行的日期时间,以便下次运行我的代码时,它只会获取比上次运行时间晚更新的数据。我正在使用带有 BULK API 调用的 simple_salesforce 库。这是我的代码:
# open json file and retrieve last_run_time
with open('last_run_time.json', 'r') as openfile:
last_run_time = json.load(openfile)
print(last_run_time)
# '2020-05-14T14:48:38Z'
# sql query
sf_data = sf.bulk.Opportunity.query("SELECT ID FROM Opportunity where CreatedDate > last_run_time AND AdPoint_Id__c <> NULL")
today_date = datetime.now()
today_date_time = today_date.strftime("%Y-%m-%d"+"T"+"%H:%M:%S"+"Z")
# save datetime in json file, overwriting the old value
with open("last_run_time.json", "w") as outfile:
json.dump(today_date_time, outfile)
我的查询引发错误IndexError: list index out of range
。如何last_run_time
在sql语句中传递变量?