def add_head_bottom(c,q,output,tag_list,option): auth = util.authinfo(c) help_string = "!-all, @-private, *-mark, #-tag, _-setting" sync_time = "Checked: %s ::: "%pretty_date(sql_update_time(c)) subtitle_string = "%s"%help_string if auth: subtitle_string=sync_time+subtitle_string help = { "valid": False, "subtitle": subtitle_string } icon = "bicon-%d.png"%((option['mark']*3)+(option['private'])) head = {"title": "Links: %d items" % len(output), "subtitle": subtitle_string, "valid": False, "icon": {"path": icon} } if len(q)==0: # all head["autocomplete"]="_" head["mods"] = { "alt": help, "ctrl": help, "cmd": help, "shift": help } else: tag_str="".join(tag_list) head["mods"] = { "ctrl": { "valid": True, "subtitle": "Set [Mark] on #%s"%tag_str, "arg": "#%s_mark=1"%tag_str}, "shift": { "valid": True, "subtitle": "Unset [Mark] on #%s"%tag_str, "arg": "#%s_mark=0"%tag_str}, "alt": { "valid": True, "subtitle": "Set [Private] on #%s"%tag_str, "arg": "#%s_private=1"%tag_str}, "cmd": { "valid": True, "subtitle": "Unset [Private] on #%s"%tag_str, "arg": "#%s_private=0"%tag_str} } output.insert(0,head) # indicator = "filter status: mark-%s, priv-%s"%(util.filter_option[option['mark']],util.filter_option[option['private']]) auth = util.authinfo(c) if auth: pinboard_url = q and 'https://pinboard.in/search/?query=%s&mine=Search+Mine'%q.replace(' ','+') or 'https://pinboard.in/' pinboard_title = q and 'Search \'%s\' in pinboard.in'%q or 'Goto Pinboard' output.append({"title": pinboard_title, "subtitle": pinboard_url, "arg": pinboard_url, "valid": True, "mods": { "alt": {"valid":False, "subtitle":pinboard_url}, "ctrl": {"valid":False, "subtitle":pinboard_url}, "cmd": {"valid":False, "subtitle":pinboard_url}, "shift": {"valid":False, "subtitle":pinboard_url} } })
def add_bookmark(args, c): (url, title) = get_browser_url_info() if url == "error": print title sys.exit(0) tag = args auth = util.authinfo(c) tag = tag.strip() add_bookmark_to_db(c, url, title, tag) if auth: qurl = urllib.quote(url.encode('utf-8')) qtitle = urllib.quote(title.encode('utf-8')) qtag = urllib.quote(tag.encode('utf-8')) encode_url = 'https://api.pinboard.in/v1/posts/add?format=json&auth_token=%s&url=%s&description=%s&tags=%s&shared=no' % ( auth, qurl, qtitle, qtag) data = urllib2.urlopen(encode_url).read() ret = json.loads(data) if ret['result_code'] == 'done': print "Successfully added : %s" % title else: print ret['result_code'] else: print "Successfully added : %s" % title
def main(): # arg parsing category = sys.argv[1] try: q = unicodedata.normalize('NFC', unicode(sys.argv[2].strip())) except: q = "" conn = util.opendb() c = conn.cursor() util.create_schema(c) auth = util.authinfo(c) (q,option) = get_option(c,q) last_q = q.split(' ')[-1] if q.startswith('_'): # option process_option(c,q) elif q.startswith('+'): # add bookmark add_bookmark(c,q) elif last_q.startswith('#') and (':' not in q): # tag expansion pbsearch_tag(c,'',last_q[1:]) else: pbsearch_sql(c,option,q) util.closedb(conn)
def add_bookmark(args,c): (url,title)=get_browser_url_info(); if url=="error": print title sys.exit(0) tag=args auth=util.authinfo(c) tag=tag.strip() add_bookmark_to_db(c,url,title,tag) if auth: qurl=urllib.quote(url.encode('utf-8')) qtitle=urllib.quote(title.encode('utf-8')) qtag=urllib.quote(tag.encode('utf-8')) encode_url='https://api.pinboard.in/v1/posts/add?format=json&auth_token=%s&url=%s&description=%s&tags=%s&shared=no'%(auth,qurl,qtitle,qtag) data = urllib2.urlopen(encode_url).read() ret = json.loads(data) if ret['result_code']=='done': print "Successfully added : %s"%title else: print ret['result_code'] else: print "Successfully added : %s"%title
def main(): # arg parsing category = sys.argv[1] try: q = unicodedata.normalize('NFC', unicode(sys.argv[2].strip())) except: q = "" conn = util.opendb() c = conn.cursor() util.create_schema(c) auth = util.authinfo(c) (q, option) = get_option(c, q) last_q = q.split(' ')[-1] if q.startswith('_'): # option process_option(c, q) elif q.startswith('+'): # add bookmark add_bookmark(c, q) elif last_q.startswith('#') and (':' not in q): # tag expansion pbsearch_tag(c, '', last_q[1:]) else: pbsearch_sql(c, option, q) util.closedb(conn)
def delete(arg,c): delete_from_db(arg,c) auth = util.authinfo(c) if auth: url = 'https://api.pinboard.in/v1/posts/delete?format=json&auth_token=%s&url=%s'%(auth,urllib.quote(arg)) data = urllib2.urlopen(url).read() ret = json.loads(data) if ret['result_code']=='done' or ret['result_code']=='item not found': print "%s deleted"%urlparse.urlparse(arg)[1] else: print ret['result_code'] else: print "%s deleted"%urlparse.urlparse(arg)[1]
def delete(arg, c): delete_from_db(arg, c) auth = util.authinfo(c) if auth: url = 'https://api.pinboard.in/v1/posts/delete?format=json&auth_token=%s&url=%s' % ( auth, urllib.quote(arg)) data = urllib2.urlopen(url).read() ret = json.loads(data) if ret['result_code'] == 'done' or ret[ 'result_code'] == 'item not found': print "%s deleted" % urlparse.urlparse(arg)[1] else: print ret['result_code'] else: print "%s deleted" % urlparse.urlparse(arg)[1]
sys.exit(0) else: # print "Loading tags completed" return tags except IOError as e: print e sys.exit(0) if __name__ == '__main__': conn = util.opendb() c = conn.cursor() util.create_schema(c) pinboard_token=util.authinfo(c) if not pinboard_token: print "Setup Pinboard authentication token" sys.exit(0) server_time = pinboard_update_time(pinboard_token) sql_time = util.sql_update_time(c) now = datetime.datetime.utcnow() if (sql_time < server_time): pins = load_pinboard_data(pinboard_token) populate_data(c,pins,now) tags = load_tags_data(pinboard_token) populate_tags(c,tags,now)
def process_option(c,q): result = [] help_back_string = "enter to go Back" help_select_string = "" mods = { "ctrl": {"valid": False, "subtitle": ""}, "alt": {"valid": False, "subtitle": ""}, "cmd": {"valid": False, "subtitle": ""}, "shift": {"valid": False, "subtitle": ""} } mark = util.filter_mark(c) private = util.filter_private(c) sort = util.sql_orderby(c) if q.startswith("_mark"): result.append({"title": "mark [filter] - "+util.filter_option[mark], "subtitle": help_back_string, "valid": False, "autocomplete":"_", "mods": mods }) add_option_submenu(result,mods,"mark",mark) elif q.startswith("_private"): result.append({"title": "private [filter] - "+util.filter_option[private], "subtitle": help_back_string, "valid": False, "autocomplete":"_", "mods": mods }) add_option_submenu(result,mods,"private",private) elif q.startswith("_sort"): result.append({"title": "sort - "+util.sort_option[sort], "subtitle": help_back_string, "valid": False, "autocomplete":"_", "mods": mods }) add_option_submenu(result,mods,"sort",sort) elif q.startswith("_pbauth"): result.append({"title": "_pbauth username:token", "subtitle": "Setup Pinboard authentication token", "valid": False, "mods": mods }) if ' ' in q and ':' in q: result[0]['valid'] = True result[0]['arg'] = '_auth='+q.split(' ')[1] result[0]['subtitle'] = "Enter to set" else: result.append({"title": "Settings", "subtitle": "enter to go Back", "valid": False, "autocomplete": "", "mods": mods }) result.append({"title": "mark [filter] - "+util.filter_option[mark], "subtitle": help_select_string, "valid": False, "autocomplete":"_mark", "mods": mods }) result.append({"title": "private [filter] - "+util.filter_option[private], "subtitle": help_select_string, "valid": False, "autocomplete":"_private", "mods": mods }) result.append({"title": "sort - "+util.sort_option[sort], "subtitle": help_select_string, "valid": False, "autocomplete":"_sort", "mods": mods }) auth = util.authinfo(c) if auth: result.append({"title": "> Pinboard User - %s"%auth.split(':')[0], "subtitle": 'enter to change', "valid": False, "autocomplete":"_pbauth ", "mods": mods }) result.append({"title": ">> Download pinboard data", "subtitle": 'enter to reload pinboard', "valid": True, "arg": "_pbreload", "autocomplete":"_pbreload ", "mods": mods }) else: result.append({"title": ">> Login Pinboard account", "subtitle": 'pbauth - username:token', "valid": False, "autocomplete":"_pbauth ", "mods": mods }) print json.dumps({"items": result})
else: # print "Loading tags completed" return tags except IOError as e: print e sys.exit(0) if __name__ == '__main__': conn = util.opendb() c = conn.cursor() util.create_schema(c) pinboard_token = util.authinfo(c) if not pinboard_token: print "Setup Pinboard authentication token" sys.exit(0) server_time = pinboard_update_time(pinboard_token) sql_time = util.sql_update_time(c) now = datetime.datetime.utcnow() if (sql_time < server_time): pins = load_pinboard_data(pinboard_token) populate_data(c, pins, now) tags = load_tags_data(pinboard_token) populate_tags(c, tags, now)
def process_option(c, q): result = [] help_back_string = "enter to go Back" help_select_string = "" mods = { "ctrl": { "valid": False, "subtitle": "" }, "alt": { "valid": False, "subtitle": "" }, "cmd": { "valid": False, "subtitle": "" }, "shift": { "valid": False, "subtitle": "" } } mark = util.filter_mark(c) private = util.filter_private(c) sort = util.sql_orderby(c) if q.startswith("_mark"): result.append({ "title": "mark [filter] - " + util.filter_option[mark], "subtitle": help_back_string, "valid": False, "autocomplete": "_", "mods": mods }) add_option_submenu(result, mods, "mark", mark) elif q.startswith("_private"): result.append({ "title": "private [filter] - " + util.filter_option[private], "subtitle": help_back_string, "valid": False, "autocomplete": "_", "mods": mods }) add_option_submenu(result, mods, "private", private) elif q.startswith("_sort"): result.append({ "title": "sort - " + util.sort_option[sort], "subtitle": help_back_string, "valid": False, "autocomplete": "_", "mods": mods }) add_option_submenu(result, mods, "sort", sort) elif q.startswith("_pbauth"): result.append({ "title": "_pbauth username:token", "subtitle": "Setup Pinboard authentication token", "valid": False, "mods": mods }) if ' ' in q and ':' in q: result[0]['valid'] = True result[0]['arg'] = '_auth=' + q.split(' ')[1] result[0]['subtitle'] = "Enter to set" else: result.append({ "title": "Settings", "subtitle": "enter to go Back", "valid": False, "autocomplete": "", "mods": mods }) result.append({ "title": "mark [filter] - " + util.filter_option[mark], "subtitle": help_select_string, "valid": False, "autocomplete": "_mark", "mods": mods }) result.append({ "title": "private [filter] - " + util.filter_option[private], "subtitle": help_select_string, "valid": False, "autocomplete": "_private", "mods": mods }) result.append({ "title": "sort - " + util.sort_option[sort], "subtitle": help_select_string, "valid": False, "autocomplete": "_sort", "mods": mods }) auth = util.authinfo(c) if auth: result.append({ "title": "> Pinboard User - %s" % auth.split(':')[0], "subtitle": 'enter to change', "valid": False, "autocomplete": "_pbauth ", "mods": mods }) result.append({ "title": ">> Download pinboard data", "subtitle": 'enter to reload pinboard', "valid": True, "arg": "_pbreload", "autocomplete": "_pbreload ", "mods": mods }) else: result.append({ "title": ">> Login Pinboard account", "subtitle": 'pbauth - username:token', "valid": False, "autocomplete": "_pbauth ", "mods": mods }) print json.dumps({"items": result})
def add_head_bottom(c, q, output, tag_list, option): auth = util.authinfo(c) help_string = "!-all, @-private, *-mark, #-tag, _-setting" sync_time = "Checked: %s ::: " % pretty_date(sql_update_time(c)) subtitle_string = "%s" % help_string if auth: subtitle_string = sync_time + subtitle_string help = {"valid": False, "subtitle": subtitle_string} icon = "bicon-%d.png" % ((option['mark'] * 3) + (option['private'])) head = { "title": "Links: %d items" % len(output), "subtitle": subtitle_string, "valid": False, "icon": { "path": icon } } if len(q) == 0: # all head["autocomplete"] = "_" head["mods"] = {"alt": help, "ctrl": help, "cmd": help, "shift": help} else: tag_str = "".join(tag_list) head["mods"] = { "ctrl": { "valid": True, "subtitle": "Set [Mark] on #%s" % tag_str, "arg": "#%s_mark=1" % tag_str }, "shift": { "valid": True, "subtitle": "Unset [Mark] on #%s" % tag_str, "arg": "#%s_mark=0" % tag_str }, "alt": { "valid": True, "subtitle": "Set [Private] on #%s" % tag_str, "arg": "#%s_private=1" % tag_str }, "cmd": { "valid": True, "subtitle": "Unset [Private] on #%s" % tag_str, "arg": "#%s_private=0" % tag_str } } output.insert(0, head) # indicator = "filter status: mark-%s, priv-%s"%(util.filter_option[option['mark']],util.filter_option[option['private']]) auth = util.authinfo(c) if auth: pinboard_url = q and 'https://pinboard.in/search/?query=%s&mine=Search+Mine' % q.replace( ' ', '+') or 'https://pinboard.in/' pinboard_title = q and 'Search \'%s\' in pinboard.in' % q or 'Goto Pinboard' output.append({ "title": pinboard_title, "subtitle": pinboard_url, "arg": pinboard_url, "valid": True, "mods": { "alt": { "valid": False, "subtitle": pinboard_url }, "ctrl": { "valid": False, "subtitle": pinboard_url }, "cmd": { "valid": False, "subtitle": pinboard_url }, "shift": { "valid": False, "subtitle": pinboard_url } } })