Last active
August 29, 2015 14:06
-
-
Save cnbeining/6c051a6a9037b7fc6474 to your computer and use it in GitHub Desktop.
Bash upload image to imgur
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
#Bash upload image to imgur | |
#Beining http://www.cnbeining.com/ | |
#NEED requests !!!!! | |
import sys | |
import os | |
import glob | |
import requests | |
from base64 import b64encode | |
url = 'https://api.imgur.com/3/image.json' | |
line_to_write_this = '' | |
headers = {"Authorization": "Client-ID **********"}#change me! | |
filelist = glob.glob('*.*')#change me! | |
print(filelist) | |
f = open('result.csv', "a") | |
for file_this in filelist: | |
print(file_this) | |
try: | |
j1 = requests.post( | |
url, | |
headers = headers, | |
data = { | |
'image': b64encode(open(file_this, 'rb').read()), | |
'type': 'base64', | |
} | |
) | |
info = json.loads(j1.text.decode('utf-8')) | |
status_this = str(info['status']) | |
link_this = str(info['data']['link']) | |
line_to_write_this = str(file_this) + ',' + link_this + ',' + status_this + '\n' | |
f.writelines(line_to_write_this) | |
print(status_this) | |
except: | |
print('ERROR') | |
line_to_write_this = ',,ERROR' + '\n' | |
f = open('result.csv', "a") | |
f.writelines(line_to_write_this) | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment