Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.34 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. #-*- coding: utf-8 -*-
  4. import os, time, sys, re, platform
  5. from datetime import datetime as dt, timedelta
  6. import pyscreenshot as ImageGrab
  7. from imgurpython import ImgurClient
  8. from subprocess import Popen, PIPE
  9.  
  10. def check_is_directory(path_to_dir):
  11.     if not os.path.exists(path_to_dir):
  12.         os.makedirs(path_to_dir)
  13.        
  14. def make_screenshot(screenshot_folder):
  15.     cur_time = dt.now()
  16.     screen_name = re.sub('[^0-9]','', str(cur_time))
  17.     screen_name += ".png"
  18.     image_file = ImageGrab.grab_to_file(screenshot_folder + screen_name)
  19.  
  20.     return screenshot_folder + screen_name
  21.  
  22. def upload_image(client, image_path):
  23.     '''
  24.        Upload a picture of a kitten. We don't ship one, so get creative!
  25.    '''
  26.  
  27.     # Here's the metadata for the upload. All of these are optional, including
  28.     # this config dict itself.
  29.  
  30.     print("Uploading image... ")
  31.     image = client.upload_from_path(image_path, None, anon=True)
  32.     print("Done")
  33.     print()
  34.  
  35.     return image
  36.    
  37. def paste(str, p=True, c=True):
  38.     from subprocess import Popen, PIPE
  39.  
  40.     if p:
  41.         p = Popen(['xsel', '-pi'], stdin=PIPE)
  42.         p.communicate(input=str)
  43.     if c:
  44.         p = Popen(['xsel', '-bi'], stdin=PIPE)
  45.         p.communicate(input=str)
  46.        
  47.        
  48. def open_browser(url):
  49.     if sys.platform=='win32':
  50.         os.startfile(url)
  51.     elif sys.platform=='darwin':
  52.         subprocess.Popen(['open', url])
  53.     else:
  54.         import webbrowser
  55.         webbrowser.open_new_tab(url)  
  56.        
  57.        
  58. ########################################################
  59.  
  60. screenshot_folder= os.getenv("HOME") + "/Screenshots/"
  61. client_id = 'a8626b7f03b52b0'
  62. client_secret = '83571fdcf04f2068ca4c9a24b451c99f7b53d7c4'
  63. client = ImgurClient(client_id, client_secret)
  64.  
  65. if "Linux" in platform.system():
  66.     is_linux = True
  67. else:
  68.     is_linux = False
  69.  
  70.  
  71. def main():
  72.     check_is_directory(screenshot_folder)
  73.     new_image_path = make_screenshot(screenshot_folder)
  74.     print("Stopa to debil")
  75.     image = upload_image(client, new_image_path)
  76.  
  77.     print("Image was posted! Go check your images you sexy beast!")
  78.     print("You can find it here: {0}".format(image['link']))
  79.    
  80.     if is_linux:
  81.         paste(bytes(image['link'], "utf-8"))
  82.     open_browser(str(image['link']))
  83.    
  84.  
  85. if  __name__ =='__main__':
  86.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement