g3x0

[rsforums.com] imgup: CLI image uploader

Jul 17th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. ####################### imgup ########################
  4. #                                                    #
  5. # imgup is an open source piece of software,         #
  6. # developed by Gecko for rstforums.com               #
  7. #                                                    #
  8. # For quick usage instructions, type the name of the #
  9. # script without passing any arguments:              #
  10. # e.g.: ./imgup.py                                   #
  11. #                                                    #
  12. ######################################################
  13.  
  14. import os
  15. import sys
  16. import json
  17.  
  18. argv = sys.argv
  19.  
  20. ## Upload the image to imgur.com
  21. def upload_imgur():
  22.     output = os.popen('curl -s -F Filedata=@' + argv[2] + ' http://imgur.com/upload').read()
  23.     data = json.loads(output)['data']
  24.     url = 'http://i.imgur.com/' + data['hash'] + '.png'
  25.    
  26.     return url
  27.  
  28. ## Upload the image to postimage.org
  29. def upload_postimage():
  30.     output = os.popen('curl -s -F upload=@' + argv[2] + ' http://postimage.org/').read()
  31.     url = output[output.find('url=')+4:-2]
  32.     url = url.replace('http://postimg.org/image/', '')
  33.     url = 'http://postimg.org/image/' + url[0:url.find('/')+1]
  34.    
  35.     return url
  36.  
  37. ## Upload the image to iceimg.com
  38. def upload_iceimg():
  39.     output = os.popen('curl -s -F img=@' + argv[2] + ' http://iceimg.com/upload.php').read()
  40.     data = json.loads(output)
  41.     url = 'http://www.iceimg.com/' + data['full'].replace('\\', '')
  42.    
  43.     return url
  44.  
  45. ## Show the usage information
  46. def show_usage():
  47.     print '[!] Usage:      imgup target local_file [clip]'
  48.     print ''
  49.     print '[*] imgup       the name of the script'
  50.     print ''
  51.     print '[*] target',
  52.     print '     all              for all the sites below'
  53.     print '                imgur or ur      for imgur.com'
  54.     print '                postimage or pi  for postimage.org'
  55.     print '                iceimg or ice    for iceimg.com'
  56.     print ''
  57.     print '[*] local_file  the path to the local image file'
  58.     print ''
  59.     print '[+] clip        copy the image URL to the clipboard'
  60.     print '                doesn\'t work if you choose to upload'
  61.     print '                the image on all the sites'
  62.     print ''
  63.     print 'e.g.            imgup ur Screenshot.png clip'
  64.     exit()
  65.  
  66. ## If there aren't enough parameters passed,
  67. ## Show the usage information
  68. if len(argv) < 3:
  69.     show_usage()
  70.  
  71. ## Show the image URL if the user chose imgur
  72. if argv[1] == 'imgur' or argv[1] == 'ur':
  73.     url = upload_imgur()
  74.  
  75. ## Show the image URL if the user chose postimage
  76. elif argv[1] == 'postimage' or argv[1] == 'pi':
  77.     url = upload_postimage()
  78.  
  79. ## Show the image URL if the user chose iceimg
  80. elif argv[1] == 'ice' or argv[1] == 'iceimg':
  81.     url = upload_iceimg()
  82.  
  83. ## Show all the image URLs if the user chose the all option
  84. elif argv[1] == 'all':
  85.     url = upload_imgur() + ',' + upload_postimage() + ',' + upload_iceimg()
  86.  
  87. ## If the option is not recognised, show the usage information
  88. else:
  89.     show_usage()
  90.  
  91. ## Show the URL(s) and copy it to the clipboard if requested
  92. if argv[1] == 'all':
  93.     print 'Image URLs:'
  94.     urls = url.split(',')
  95.    
  96.     for u in urls:
  97.         print u
  98. else:
  99.     print 'Image URL: ' + url,
  100.    
  101.     if len(argv) == 4:
  102.         os.system('echo ' + url.strip() + ' | pbcopy')
  103.         print '(copied to clipboard)'
Advertisement
Add Comment
Please, Sign In to add comment