-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgur.py
More file actions
29 lines (19 loc) · 814 Bytes
/
imgur.py
File metadata and controls
29 lines (19 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from urllib.request import urlopen, Request, urlretrieve
from urllib.parse import urlencode
from base64 import standard_b64encode
from json import loads
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
print(os.path.abspath(__file__))
url = "https://pbs.twimg.com/media/E5hTaZLWYAMU6ir.jpg"
urlretrieve(url, "daily.jpg")
f = open("./daily.jpg", "rb")
b64_image = standard_b64encode(f.read())
client_id = "4d8b88de7160b18" # put your client ID here
headers = {'Authorization': 'Client-ID ' + client_id}
data = {'image': b64_image, 'title': 'test'} # create a dictionary.
request = Request(url="https://api.imgur.com/3/upload.json", data=urlencode(data).encode("utf-8"),headers=headers)
print(request)
response = urlopen(request).read()
parse = loads(response)
print(parse['data']['link'])