-
Notifications
You must be signed in to change notification settings - Fork 3
Description
"""
dog_image_uploader.ru
Скрипт для скачивания изображений собак по породе и загрузки их на Яндекс.Диск
"""
import os
import requests
os.makedirs('images', exist_ok=True)
breed = input("Порода: ").strip().lower()
response = requests.get(f'https://dog.ceo/api/breed/{breed}/images/random')
data = response.json()
if data.get('status') == 'error':
print("Порода не найдена")
exit()
image_url = data['message']
filename = image_url.split('/')[-1]
image_path = f'images/{filename}'
with open(image_path, 'wb') as f:
f.write(requests.get(image_url).content)
print(f"Сохранено: {image_path}")
token = "y0__xCsm5WUBhjblgMgrfyfsxUwh9Xh2ge4DS8znapfUZKCB5ZOGRlFoqEPvA"
headers = {'Authorization': f'OAuth {token}'}
requests.put('https://cloud-api.yandex.net/v1/disk/resources',
headers=headers,
params={'path': 'images'})
upload = requests.get('https://cloud-api.yandex.net/v1/disk/resources/upload',
headers=headers,
params={'path': f'images/{filename}', 'overwrite': 'true'}).json()
with open(image_path, 'rb') as f:
requests.put(upload['href'], files={'file': f})
print("Загружено на Яндекс.Диск")