mirror of
https://github.com/runyanjake/memegraph.git
synced 2025-10-05 07:27:30 -07:00
23 lines
616 B
Python
23 lines
616 B
Python
import os
|
|
import requests
|
|
import json
|
|
|
|
def download_image(input_data):
|
|
input_data = input_data.replace("'", '"')
|
|
|
|
data = json.loads(input_data)
|
|
url = data['url']
|
|
|
|
response = requests.get(url)
|
|
if response.status_code == 200:
|
|
output_dir = 'output'
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
image_path = os.path.join(output_dir, url.split("/")[-1])
|
|
with open(image_path, 'wb') as f:
|
|
f.write(response.content)
|
|
print(f"Image saved to {image_path}")
|
|
return image_path
|
|
else:
|
|
print("Failed to download image.")
|
|
return None
|