Код: Выделить всё
import requests
import hashlib
import logging
from datetime import datetime
from time import sleep as s
import discord_webhook
logging.basicConfig(level=logging.DEBUG)
webhook_url = "redacted"
webhook = discord_webhook.DiscordWebhook(url=webhook_url)
url = "redacted"
response = requests.get(url)
ct = datetime.now().strftime("%m-%d_%H-%M-%S")
fn = f"redacted_{ct}.jpg"
with open(fn, "wb") as f:
f.write(response.content)
print(f"Image downloaded: {fn}")
try:
while True:
with open(fn, "rb") as f:
webhook.add_file(file=f.read(), filename="image.jpg")
resp = webhook.execute()
if resp.status_code == 200:
break
print(f"{fn} uploaded!")
except Exception as e:
print(e)
if response.status_code == 200:
existing_hash = hashlib.md5(response.content).hexdigest()
while True:
s(30)
response = requests.get(url)
if response.status_code == 200:
new_hash = hashlib.md5(response.content).hexdigest()
if new_hash != existing_hash:
ct = datetime.now().strftime("%m-%d_%H-%M-%S")
fn = f"redacted_{ct}.jpg"
with open(fn, "wb") as f:
f.write(response.content)
print(f"Image downloaded: {fn}")
try:
while True:
with open(fn, "rb") as f:
webhook.add_file(file=f.read(), filename="image.jpg")
resp = webhook.execute()
if resp.status_code == 200:
break
print(f"{fn} uploaded!")
except Exception as e:
print(e)
existing_hash = new_hash
continue
else:
print("Image is unchanged")
Подробнее здесь: https://stackoverflow.com/questions/791 ... -responses
Мобильная версия