예제 #1
0
def show():
    text = clipboard.read_primary()
    if not text:
        print("Warning! The primary clipboard is empty.")
        return
    #
    context = {"link": text}
    fname = "/tmp/{id}.html".format(id=simpleflake.simpleflake(hexa=True))

    with open(fname, "w") as f:
        html = render_template("link.html", context)
        f.write(html)

    common.open_url(fname)
예제 #2
0
def get_new_item():
    myid = simpleflake()
    doc = raw_input("doc: ").strip()
    action = raw_input("action: (c)at or (o)pen_url [c/o]? ").strip()
    if action not in ('c', 'o'):
        print("Error: invalid input.")
        sys.exit(1)
    action_value = None
    if action == 'c':
        action_text = "cat"
        print("Choose category:")
        db = get_db()
        action_value = raw_input("  filename: ").strip()
        action_value = "{db}/{av}".format(db=db, av=action_value)
        fname = "{root}/data/{db}/{f}".format(root=cfg.ROOT, db=db, f=action_value)
        if os.path.isfile(fname):
            print("Error: the file {fname} already exists.".format(fname=fname))
            sys.exit(1)
        dbfile = "{root}/data/{db}.json".format(root=cfg.ROOT, db=db)
    else:
        action_text = "open_url"
        action_value = raw_input("  open_url: ").strip()
        db = "urls"
        dbfile = "{root}/data/urls.json".format(root=cfg.ROOT)
    #
    tags = [tag.strip() for tag in raw_input("tags: ").split(",")]

    with open(dbfile) as f:
        dbdict = json.load(f, object_pairs_hook=OrderedDict)

    dbdict[myid] = OrderedDict()
    d = dbdict[myid]
    d["doc"] = doc
    d["meta"] = {
        "date": get_timestamp_from_year_to_second(),
        "author": getpass.getuser()
    }
    d["action"] = [action_text, action_value]
    d["tags"] = tags
    d["extra"] = []
    #
    return d, dbdict, db