Esempio n. 1
0
def main(clear_conf=('c', False, 'Rewrite example config and noise'),
         dropbox_login=('d', False, 'Login to dropbox')):
    if dropbox_login:
        settings.dropbox_login()
        return
    if clear_conf:
        utils.install()
        return

    local_image = utils.screenshot()
    assert os.path.exists(local_image)
    filename = utils.get_filename()
    url = upload.upload(local_image, filename)
    print(url)
    utils.set_clipboard(url)
    conf = settings.get_conf()
    if conf.get('file').as_bool('keep'):
        dest_dir = os.path.expanduser(conf['file']['dir'])
        if not os.path.exists(dest_dir):
            os.mkdir(dest_dir)
        dest = os.path.join(dest_dir, filename)
        shutil.move(local_image, dest)
    else:
        os.unlink(local_image)

    if conf.get('upload').as_bool('noise'):
        utils.play_noise()
Esempio n. 2
0
#coding: utf-8

import base64
import dropbox as dropbox_lib
import requests
from craption import settings
import subprocess

conf = settings.get_conf()
def upload(path, filename):
    if conf['upload']['upload']:
        to = conf['upload']['to'].lower()
        if to == "imgur":
                return(imgur(path, conf['upload']['imgur']['api-key']))
        elif to == "scp":
                return(scp(path, filename, conf['upload']['scp']))
        elif to == "dropbox":
                return(dropbox(path, filename, conf['upload']['dropbox']))


def dropbox(local_path, filename, dropconf):
    print (dropconf)
    client = dropbox_lib.client.DropboxClient(dropconf['token'])
    uploaded = client.put_file("/" + filename, open(local_path))
    return client.share(uploaded['path'])['url']

def imgur(path, api_key):
    img_data = base64.b64encode(open(path).read())
    data = {
        'key': api_key,
        'image': img_data