Reputation: 65
The script is simple:
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)})
How do I get this code to run? What's the issue here?
Upvotes: 2
Views: 1695
Reputation: 8064
Zapier expects the output of the script to be a JSON-serializable object (h/t to Michael Case from the comments section).
Furthermore, the script is not indented properly. Python is an indentation-sensitive language, i.e. indentation matters.
Try something like this:
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)}
Upvotes: 2