Example #1
0
def start():
    s = get_secret_key()
    print("-" * len(s))
    print(s)
    print("-" * len(s))
    text_to_clipboards(s)
    print()
Example #2
0
def show_short_url(short_url, long_url=None, expanded=None):
    print(cindex(short_url, color=cfg.colors[cfg.g.BACKGROUND]["cindex"]))
    if long_url and expanded:
        expanded = simplify_url(expanded)
        if expanded == long_url:
            feedback = cindex("(match)", color="green")
        else:
            feedback = cindex("(differs)", color="red")
        print('# expanded from shortened URL: {url} {f}'.format(url=expanded, f=feedback))
    text_to_clipboards(short_url)
    print("# use show() to zoom in")
Example #3
0
def shorten_url(long_url):
    try:
        url = "https://www.googleapis.com/urlshortener/v1/url"
        data = {"longUrl": long_url}
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        r = requests.post(url, data=json.dumps(data), headers=headers)
        short = r.json()["id"]
        print(short)
        text_to_clipboards(short)
    except:
        print("Hmm, strange...")
Example #4
0
def to_clipboards(key):
    if fs.which("xsel"):
        o = hdict[key]
        #
        action = o["action"]
        verb = action[0]
        if verb == 'cat':
            with open("data/" + action[1]) as f:
                text_to_clipboards(f.read().rstrip("\n"))
    else:
        print("Warning: xsel is not installed, cannot copy to clipboards.")
Example #5
0
def path_to_clipboards(key):
    if fs.which("xsel"):
        o = hdict[key]
        #
        action = o["action"]
        verb = action[0]
        if verb == 'cat':
            f = os.path.abspath("data/" + action[1])
            print('#', f)
            text_to_clipboards(f)
    else:
        print("Warning: xsel is not installed, cannot copy to clipboards.")
Example #6
0
def process_extras(fname, o):
    """
    Currently implemented extras:
    * cb()    -> copy file content to the clipboards
    """
    extra = o.get("extra")
    if not extra:
        return
    # else
    for e in extra:
        if e == "cb()":
            text_to_clipboards(open(fname).read().rstrip("\n"))
        else:
            print("Warning: unknown extra option: {e}".format(e=e))
Example #7
0
def start(url=None):
    """
    Install a Python package directly from GitHub.
    """
    if not url:
        try:
            url = raw_input("GitHub URL of the project: ")
        except (KeyboardInterrupt, EOFError):
            print()
            return

    project_name = url[url.rfind('/')+1:]
    cmd = 'pip install -e git+{url}.git#egg={pn}'.format(url=url, pn=project_name)
    print(cmd)
    text_to_clipboards(cmd)
Example #8
0
def main():
    normal = False
    if "-n" in sys.argv:
        normal = True
        sys.argv.remove("-n")

    if len(sys.argv) == 1:
        text = os.getcwd()
    else:
        text = os.path.join(os.getcwd(), sys.argv[1])

    if not normal:
        text = text.replace(' ', r'\ ')
    print('# copied to the clipboard', file=sys.stderr)
    print(text)
    text_to_clipboards(text)
Example #9
0
def do_action(lines, action):
    """
    We have some lines from a file and perform an action on them.

    TODO: it's not yet ready. When I meet new needs, I will extend this method.
    """
    text = ''.join(lines).rstrip('\n')
    if action == 'cb':
        # copy text to clipboard
        text_to_clipboards(text)
    elif action == 'cb(>)':
        # add 4 leading spaces to each line (facilitate code insert in markdown)
        text = '\n'.join(['    ' + line for line in text.split('\n')])
        text_to_clipboards(text)
    elif action == 'sh':
        if len(lines) == 1:
            if text.startswith('$ '):
                text = text[2:]
            os.system(text)
        else:
            print('Warning! This action is not yet implemented.')
            print("Check out the selected_lines.py file's do_action() method.")
Example #10
0
def username_password():
    """
    Generate username and password.

    This is used for online registrations.
    The function has a static variable called
    "password", set in init().
    If you provide your email in the file
    email.txt, you can also copy it to the
    clipboards.
    """
    username = userpass.get_username()
    password = userpass.get_password(length=12)
    try:
        email = open("{root}/email.txt".format(root=cfg.ROOT)).read().strip()
    except IOError:
        email = None

    print("""
[1] {u:21} (username, copy to clipboard)
[2] {p:21} (password, copy to clipboard)
[3] {e:21} (email, copy to clipboard)
[q] <<
""".strip().format(u=username, p=password, e=email))
    while True:
        try:
            inp = raw_input("~~> ").strip()
        except (KeyboardInterrupt, EOFError):
            print()
            return
        if len(inp) == 0:
            continue
        elif inp == 'q':
            return
        elif inp == 'qq':
            common.my_exit(0)
        elif inp == '1':
            text_to_clipboards(username, prefix="username")
        elif inp == '2':
            text_to_clipboards(password, prefix="password")
            username_password.password = password
        elif inp == '3':
            if email:
                text_to_clipboards(email, prefix="email")
            else:
                print("Warning! You have no email specified.")
                print("Tip: create an email.txt file in the PrimCom folder.")
        else:
           print('Wat?')
Example #11
0
def show_my_ip():
    r = requests.get("http://jsonip.com/")
    ip = r.json()["ip"]
    print(ip)
    text_to_clipboards(ip)
Example #12
0
def main():
    text = os.path.split(os.getcwd())[1]
    print('# copied to the clipboard', file=sys.stderr)
    print(text)
    text_to_clipboards(text)