pomf.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python2
  2. #coding: utf8
  3. '''
  4. Modified version of Jirx's script.
  5. ** You need to install
  6. * python2-requests
  7. * python2-notify
  8. * xclip
  9. * scrot
  10. # It makes a directory in your home folder called screenshots and saves screenshots there.
  11. '''
  12. try:
  13. import requests
  14. except ImportError:
  15. exit("Install python2-requests")
  16. try:
  17. import pynotify
  18. except ImportError:
  19. exit("Install python2-notify")
  20. import os
  21. import subprocess
  22. import time
  23. from sys import argv
  24. import getopt
  25. ### Edit ###
  26. screenshot_dir = os.getenv("HOME") + os.path.sep + "Imágenes/Screenshots" + os.path.sep
  27. image_directory = "http://a.pomf.se/"
  28. upload_script = "http://pomf.se/upload.php"
  29. ############
  30. def main():
  31. try:
  32. if not os.path.exists(screenshot_dir):
  33. os.makedirs(screenshot_dir)
  34. except Exception as e:
  35. notify("Error creating directory {0}, {1}".format(screenshot_dir), e)
  36. exit()
  37. try:
  38. response = requests.post(
  39. url=upload_script,
  40. files={"files[]":open(file_upload, "r")}
  41. )
  42. except Exception as e:
  43. notify("Error uploading {0}".format(e))
  44. exit()
  45. response = response.text.split('"')
  46. response_text = response[17]
  47. notify(image_directory + response_text)
  48. clipboard(image_directory + response_text)
  49. print image_directory + response_text
  50. def notify(message):
  51. pynotify.init(message)
  52. notifyme=pynotify.Notification (message)
  53. notifyme.show ()
  54. def clipboard(message):
  55. p = subprocess.Popen(
  56. ["xclip", "-selection", "c"],
  57. stdout=subprocess.PIPE,
  58. stdin=subprocess.PIPE
  59. )
  60. p.stdin.write(message)
  61. def Usage():
  62. print "Usage: pomf [OPTION]... [FILE]\n"
  63. print " -f, --file \tUploads a file to pomf.se"
  64. print " -i, --image \tUploads a image using scrot --select and uploads the image to pomf.se"
  65. print "\n Example:\n\t pomf -f pomf.flac"
  66. print " \t Uploads a file via scrot --select and notifies you once it's done.\n"
  67. exit()
  68. if len(argv) == 1:
  69. Usage()
  70. try:
  71. opts, args = getopt.getopt(argv[1:], "hif", ["help", "image","file="])
  72. except getopt.GetoptError, err:
  73. print("Error! Argument is invalid\n")
  74. Usage()
  75. for o, a in opts:
  76. if o in ("-h","--help"):
  77. Usage()
  78. elif o in ("-i","--image"):
  79. file_upload = "{0}{1}.png".format(screenshot_dir, int(time.time()))
  80. p = subprocess.Popen(["scrot", "--select", file_upload])
  81. p.wait()
  82. elif o in ("-f","--file"):
  83. file_upload = argv[2]
  84. else:
  85. Usage()
  86. if __name__ == "__main__":
  87. main()