Created
June 14, 2022 20:37
-
-
Save BernardoGO/6fcbab9350fb3eba357d2bb30058b261 to your computer and use it in GitHub Desktop.
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 base64 | |
import json | |
import requests | |
URL = 'https://api.imgur.com/3/image' | |
AUTHORIZATION = 'Client-ID c9a6efb3d7932fd' | |
with open("download.png", 'rb') as f: | |
image = base64.b64encode(f.read()) | |
def imgur(images): | |
session = requests.Session() | |
session.headers['Authorization'] = AUTHORIZATION | |
for image in images: | |
response = session.post(URL, data=image) | |
if response.status_code >= 400: | |
print ('Failed to upload image') | |
continue | |
url = response.json()['data']['link'] | |
print(url) | |
imgur([image]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment