Advertisement
Guest User

Imgur Upload.pys

a guest
Jun 16th, 2011
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. def upload(item):
  2.  
  3.     from json import loads as json_decode
  4.     from urllib import urlencode
  5.     from urllib2 import Request, urlopen
  6.     import base64
  7.  
  8.     url = 'http://api.imgur.com/2/upload.json'
  9.     key = 'b3625162d3418ac51a9ee805b1840452'
  10.  
  11.     image = file(item.path, 'rb').read()
  12.     data = {'key': key,
  13.             'image': base64.b64encode(image),
  14.             'path': item.path}
  15.  
  16.     try:
  17.         req = urlopen(Request(url, urlencode(data)))
  18.     except Exception, e:
  19.         Salamander.MsgBox(e)
  20.    
  21.     response = json_decode(req.read())
  22.    
  23.     fm = Salamander.Forms.Form(item.name + ' Links:')
  24.     fm.l1 = Salamander.Forms.Label('Direct Link')
  25.     fm.t1 = Salamander.Forms.TextBox(response['upload']['links']['original'])
  26.     fm.l2 = Salamander.Forms.Label('Forum (BB Code) Link')
  27.     fm.t2 = Salamander.Forms.TextBox('[url=%s][img]%s[/img][/url]' \
  28.             % (response['upload']['links']['original'], response['upload']['links']['small_square']))
  29.     fm.l3 = Salamander.Forms.Label('Small Thumbnail')
  30.     fm.t3 = Salamander.Forms.TextBox(response['upload']['links']['small_square'])
  31.     fm.l4 = Salamander.Forms.Label('Imgur Page')
  32.     fm.t4 = Salamander.Forms.TextBox(response['upload']['links']['imgur_page'])
  33.     fm.l5 = Salamander.Forms.Label('Delete Page')
  34.     fm.t5 = Salamander.Forms.TextBox(response['upload']['links']['delete_page'])
  35.     fm.Execute()
  36.  
  37.  
  38. if Salamander.SourcePanel.PathType == 1:
  39.     item = Salamander.SourcePanel.FocusedItem;
  40.  
  41. chk = Salamander.QuestionDialog(item, "Upload this file to Imgur.com?", 5, 'Automation script: Imgur upload')
  42.  
  43. if chk == 6: upload(item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement