Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def upload(item):
- from json import loads as json_decode
- from urllib import urlencode
- from urllib2 import Request, urlopen
- import base64
- url = 'http://api.imgur.com/2/upload.json'
- key = 'b3625162d3418ac51a9ee805b1840452'
- image = file(item.path, 'rb').read()
- data = {'key': key,
- 'image': base64.b64encode(image),
- 'path': item.path}
- try:
- req = urlopen(Request(url, urlencode(data)))
- except Exception, e:
- Salamander.MsgBox(e)
- response = json_decode(req.read())
- fm = Salamander.Forms.Form(item.name + ' Links:')
- fm.l1 = Salamander.Forms.Label('Direct Link')
- fm.t1 = Salamander.Forms.TextBox(response['upload']['links']['original'])
- fm.l2 = Salamander.Forms.Label('Forum (BB Code) Link')
- fm.t2 = Salamander.Forms.TextBox('[url=%s][img]%s[/img][/url]' \
- % (response['upload']['links']['original'], response['upload']['links']['small_square']))
- fm.l3 = Salamander.Forms.Label('Small Thumbnail')
- fm.t3 = Salamander.Forms.TextBox(response['upload']['links']['small_square'])
- fm.l4 = Salamander.Forms.Label('Imgur Page')
- fm.t4 = Salamander.Forms.TextBox(response['upload']['links']['imgur_page'])
- fm.l5 = Salamander.Forms.Label('Delete Page')
- fm.t5 = Salamander.Forms.TextBox(response['upload']['links']['delete_page'])
- fm.Execute()
- if Salamander.SourcePanel.PathType == 1:
- item = Salamander.SourcePanel.FocusedItem;
- chk = Salamander.QuestionDialog(item, "Upload this file to Imgur.com?", 5, 'Automation script: Imgur upload')
- if chk == 6: upload(item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement