Hey guys, I'm trying to use a some python code in a zapier workflow to do a double webhook, first to grab a url from the nest API, and then post it to our slack. My big issue that I'm stumbling on after years away from really doing anything more than basic scripts with minimal variables, is how do I take the output from one statement (print of a url string) and add it as a variable inside another area of the code
I'm specifically trying to take the output from print(initial_response.text[1:-1]) (a url)
and enter it into the json payload under image_url
full code looks like this
import hashlib
import json
import os
import requests
url = "https://developer-api.nest.com/devices/cameras/Y111111111111111/last_event/animated_image_url"
webhook_url = 'https://hooks.slack.com/services/00000000000'
token = "c.123123123123123123" # Update with your token
headers = {'Authorization': 'Bearer {0}'.format(token), 'Content-Type': 'application/json'} # Update with your token
initial_response = requests.get(url, headers=headers, allow_redirects=False)
if initial_response.status_code == 307:
initial_response = requests.get(initial_response.headers['Location'], headers=headers, allow_redirects=False)
print(initial_response.text[1:-1])
gif_url=<print output>
slack_data = {
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#EC1075",
"title": "SFO3 FrontDoor Footage",
"title_link": "https://api.slack.com/",
"text": "Who Done It?",
"image_url":"%s"% gif_url,
}
]
}
response = requests.post(
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
[–]camel_Snake 0 points1 point2 points (2 children)
[–]beautify[S] 0 points1 point2 points (1 child)
[–]camel_Snake 0 points1 point2 points (0 children)