Skip to content

Instantly share code, notes, and snippets.

@olimorris
Created May 31, 2024 16:23
Show Gist options
  • Save olimorris/41c887527f23fef3c252f6e923351d2c to your computer and use it in GitHub Desktop.
Save olimorris/41c887527f23fef3c252f6e923351d2c to your computer and use it in GitHub Desktop.
Using Python to download code in Automation 360
import requests
import os
# URL of the API endpoint
url = "https://httpbin.org/image/png"
def download():
# Make the GET request
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Get the user's home directory
home_dir = os.path.expanduser("~")
# Construct the path to the Desktop
desktop_path = os.path.join(home_dir, "Desktop", "image.png")
# Open a file in write-binary mode
with open(desktop_path, "wb") as file:
# Write the binary content of the response to the file
file.write(response.content)
print(f"File downloaded to {desktop_path}")
else:
print(f"Failed to download file. Status code: {response.status_code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment