Created
May 31, 2024 16:23
-
-
Save olimorris/41c887527f23fef3c252f6e923351d2c to your computer and use it in GitHub Desktop.
Using Python to download code in Automation 360
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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