Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- #-*- coding: utf-8 -*-
- import os, time, sys, re, platform
- from datetime import datetime as dt, timedelta
- import pyscreenshot as ImageGrab
- from imgurpython import ImgurClient
- from subprocess import Popen, PIPE
- def check_is_directory(path_to_dir):
- if not os.path.exists(path_to_dir):
- os.makedirs(path_to_dir)
- def make_screenshot(screenshot_folder):
- cur_time = dt.now()
- screen_name = re.sub('[^0-9]','', str(cur_time))
- screen_name += ".png"
- image_file = ImageGrab.grab_to_file(screenshot_folder + screen_name)
- return screenshot_folder + screen_name
- def upload_image(client, image_path):
- '''
- Upload a picture of a kitten. We don't ship one, so get creative!
- '''
- # Here's the metadata for the upload. All of these are optional, including
- # this config dict itself.
- print("Uploading image... ")
- image = client.upload_from_path(image_path, None, anon=True)
- print("Done")
- print()
- return image
- def paste(str, p=True, c=True):
- from subprocess import Popen, PIPE
- if p:
- p = Popen(['xsel', '-pi'], stdin=PIPE)
- p.communicate(input=str)
- if c:
- p = Popen(['xsel', '-bi'], stdin=PIPE)
- p.communicate(input=str)
- def open_browser(url):
- if sys.platform=='win32':
- os.startfile(url)
- elif sys.platform=='darwin':
- subprocess.Popen(['open', url])
- else:
- import webbrowser
- webbrowser.open_new_tab(url)
- ########################################################
- screenshot_folder= os.getenv("HOME") + "/Screenshots/"
- client_id = 'a8626b7f03b52b0'
- client_secret = '83571fdcf04f2068ca4c9a24b451c99f7b53d7c4'
- client = ImgurClient(client_id, client_secret)
- if "Linux" in platform.system():
- is_linux = True
- else:
- is_linux = False
- def main():
- check_is_directory(screenshot_folder)
- new_image_path = make_screenshot(screenshot_folder)
- print("Stopa to debil")
- image = upload_image(client, new_image_path)
- print("Image was posted! Go check your images you sexy beast!")
- print("You can find it here: {0}".format(image['link']))
- if is_linux:
- paste(bytes(image['link'], "utf-8"))
- open_browser(str(image['link']))
- if __name__ =='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement