脚本很简单:
import datetime
import json
today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
if 15 <= next_thursday.day <= 21:
next_third_thursday = next_thursday
break
else:
next_date = next_thursday + datetime.timedelta(days=1)
next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))
return json.dumps({'date': str(next_third_thursday)})
如何使此代码运行?这是什么问题?
答案 0 :(得分:2)
Zapier希望脚本的输出是JSON可序列化的对象(从注释部分向Michael Case致谢)。
此外,脚本未正确缩进。 Python是一种缩进敏感的语言,即缩进很重要。
尝试这样的事情:
import datetime
today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
if 15 <= next_thursday.day <= 21:
next_third_thursday = next_thursday
break
else:
next_date = next_thursday + datetime.timedelta(days=1)
next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))
return {'date': str(next_third_thursday)}