Revisions
-
dlo revised this gist
Jun 6, 2013 . 1 changed file with 11 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,14 +40,17 @@ # (optional) A tag that you want to export by tag = None # Your password password = "" # Alternatively (if on OS X), use the Mac OS X keychain # keychain_process = subprocess.Popen(["security", "find-internet-password", "-s", "pinboard.in", "-w"], # stdout=subprocess.PIPE) # trim_newlines = subprocess.Popen(["tr", "-d", "'\n'"], # stdin=keychain_process.stdout, # stdout=subprocess.PIPE) # keychain_process.stdout.close() # password, _ = trim_newlines.communicate() url = None bookmark_format = u"""<a href="{href}" title="{extended}">{description}</a>\n""" -
dlo revised this gist
Jun 6, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ # Your timezone local_timezone = "America/Los_Angeles" # (optional) A tag that you want to export by tag = None # Use the Mac OS X keychain -
dlo revised this gist
Jun 6, 2013 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,9 +27,17 @@ from dateutil import parser as date_parser # Settings # Your Pinboard username username = "" # The path where you'd like to store your HTML export bookmark_filename = "/Users/dan/Dropbox/PinboardBookmarks.html" # Your timezone local_timezone = "America/Los_Angeles" # A tag that you want to export by tag = None # Use the Mac OS X keychain -
dlo revised this gist
Jun 6, 2013 . 1 changed file with 11 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,7 @@ username = "dlo" bookmark_filename = "/Users/dan/Dropbox/PinboardBookmarks.html" local_timezone = "America/Los_Angeles" tag = None # Use the Mac OS X keychain keychain_process = subprocess.Popen(["security", "find-internet-password", "-s", "pinboard.in", "-w"], @@ -50,7 +51,10 @@ def quote(text): try: timestamp = os.stat(bookmark_filename).st_mtime except OSError: if tag: url = "https://api.pinboard.in/v1/posts/all?format=json&tag={}".format(tag) else: url = "https://api.pinboard.in/v1/posts/all?format=json" else: last_modified_local_time = datetime.fromtimestamp(timestamp, \ pytz.timezone(local_timezone)) @@ -62,8 +66,12 @@ def quote(text): last_modified_on_server = date_parser.parse(response.json()['update_time']) if last_modified_on_server > last_modified: if tag: url = "https://api.pinboard.in/v1/posts/all?format=json&fromdt={}&tag={}" \ .format(last_modified.strftime("%FT%TZ"), tag) else: url = "https://api.pinboard.in/v1/posts/all?format=json&fromdt={}" \ .format(last_modified.strftime("%FT%TZ")) finally: if url is not None: response = requests.get(url, auth=basic_auth) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 31 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,20 @@ #!/usr/bin/env python """ This script is designed to generate a simple html file with _all_ of your Pinboard.in bookmarks The HTML file can be added to Launchbar's index as a custom bookmark file and you can search your entire Pinboard.in collection instantly from Launchbar (by title only). It includes any applied tags as part of the title to aid in searching. You should edit the `username`, `bookmark_filename`, and `local_timezone` variables to suit your preferences. Requirements: * pytz * requests * dateutil """ from datetime import datetime @@ -25,38 +26,49 @@ import requests from dateutil import parser as date_parser # Settings username = "dlo" bookmark_filename = "/Users/dan/Dropbox/PinboardBookmarks.html" local_timezone = "America/Los_Angeles" # Use the Mac OS X keychain keychain_process = subprocess.Popen(["security", "find-internet-password", "-s", "pinboard.in", "-w"], stdout=subprocess.PIPE) trim_newlines = subprocess.Popen(["tr", "-d", "'\n'"], stdin=keychain_process.stdout, stdout=subprocess.PIPE) keychain_process.stdout.close() password, _ = trim_newlines.communicate() url = None bookmark_format = u"""<a href="{href}" title="{extended}">{description}</a>\n""" basic_auth = (username, password) def quote(text): return cgi.escape(text, quote=True).replace("\n", " ") try: timestamp = os.stat(bookmark_filename).st_mtime except OSError: url = "https://api.pinboard.in/v1/posts/all?format=json" else: last_modified_local_time = datetime.fromtimestamp(timestamp, \ pytz.timezone(local_timezone)) last_modified = last_modified_local_time.astimezone(pytz.timezone("UTC")) # Check if bookmarks have been updated remotely since last local update response = requests.get("https://api.pinboard.in/v1/posts/update?format=json", auth=basic_auth) last_modified_on_server = date_parser.parse(response.json()['update_time']) if last_modified_on_server > last_modified: url = "https://api.pinboard.in/v1/posts/all?format=json&fromdt={}" \ .format(last_modified.strftime("%FT%TZ")) finally: if url is not None: response = requests.get(url, auth=basic_auth) with open(bookmark_filename, 'a+') as bookmark_file: for bookmark in response.json(): bookmark['description'] = quote(bookmark['description']) bookmark['extended'] = quote(bookmark['extended']) bookmark_file.write(bookmark_format.format(**bookmark).encode("utf-8")) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,11 @@ #!/usr/bin/env python """ This script is designed to generate a simple html file with _all_ of your Pinboard.in bookmarks The HTML file can be added to Launchbar's index as a custom bookmark file and you can search your entire Pinboard.in collection instantly from Launchbar (by title only). It includes any applied tags as part of the title to aid in searching. Requirements: * pytz -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,7 @@ from datetime import datetime import subprocess import os import cgi import pytz import requests @@ -25,8 +26,8 @@ password, _ = trim_newlines.communicate() username = "dlo" bookmark_format = u"""<a href="{href}" title="{extended}">{description}</a>\n""" bookmark_filename = "/Users/dan/Dropbox/PinboardBookmarks.html" local_timezone = "America/Los_Angeles" basic_auth = (username, password) @@ -50,5 +51,7 @@ response = requests.get(url, auth=basic_auth) with open(bookmark_filename, 'a+') as bookmark_file: for bookmark in response.json(): bookmark['description'] = cgi.escape(bookmark['description'], quote=True).replace("\n", " ") bookmark['extended'] = cgi.escape(bookmark['extended'], quote=True).replace("\n", " ") bookmark_file.write(bookmark_format.format(**bookmark).encode("utf-8")) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ finally: if url is not None: response = requests.get(url, auth=basic_auth) with open(bookmark_filename, 'a+') as bookmark_file: for bookmark in response.json(): bookmark_file.write(bookmark_format.format(**bookmark).encode("utf-8")) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ url = None try: timestamp = os.stat(bookmark_filename).st_mtime except OSError: url = "https://api.pinboard.in/v1/posts/all?format=json" else: last_modified_local_time = datetime.fromtimestamp(timestamp, pytz.timezone(local_timezone)) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,6 @@ try: timestamp = os.stat(bookmark_filename).st_mtime except IOError: url = "https://api.pinboard.in/v1/posts/all?format=json" else: last_modified_local_time = datetime.fromtimestamp(timestamp, pytz.timezone(local_timezone)) -
dlo revised this gist
Jan 24, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,9 @@ * pytz * requests * dateutil You should edit the username, bookmark_filename, and local_timezone variables to suit your preferences. """ from datetime import datetime @@ -49,3 +52,4 @@ with open(bookmark_filename, 'a') as bookmark_file: for bookmark in response.json(): bookmark_file.write(bookmark_format.format(**bookmark).encode("utf-8")) -
dlo revised this gist
Jan 24, 2013 . 2 changed files with 51 additions and 68 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/usr/bin/env python """ Requirements: * pytz * requests * dateutil """ from datetime import datetime import subprocess import os import pytz import requests from dateutil import parser as date_parser keychain_process = subprocess.Popen(["security", "find-internet-password", "-s", "pinboard.in", "-w"], stdout=subprocess.PIPE) trim_newlines = subprocess.Popen(["tr", "-d", "'\n'"], stdin=keychain_process.stdout, stdout=subprocess.PIPE) keychain_process.stdout.close() password, _ = trim_newlines.communicate() username = "dlo" bookmark_format = u"<a href='{href}' title='{extended}'>{description}</a>" bookmark_filename = "~/Dropbox/PinboardBookmarks.html" local_timezone = "America/Los_Angeles" basic_auth = (username, password) url = None try: timestamp = os.stat(bookmark_filename).st_mtime except IOError: last_modified_on_server = None url = "https://api.pinboard.in/v1/posts/all?format=json" else: last_modified_local_time = datetime.fromtimestamp(timestamp, pytz.timezone(local_timezone)) last_modified = last_modified_local_time.astimezone(pytz.timezone("UTC")) # Check if bookmarks have been updated remotely since last local update response = requests.get("https://api.pinboard.in/v1/posts/update?format=json", auth=basic_auth) last_modified_on_server = date_parser.parse(response.json()['update_time']) if last_modified_on_server > last_modified: url = "https://api.pinboard.in/v1/posts/all?format=json&fromdt={}".format(last_modified.strftime("%FT%TZ")) finally: if url is not None: response = requests.get(url, auth=basic_auth) with open(bookmark_filename, 'a') as bookmark_file: for bookmark in response.json(): bookmark_file.write(bookmark_format.format(**bookmark).encode("utf-8")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,68 +0,0 @@ -
ttscoff created this gist
Sep 24, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/usr/bin/ruby =begin This script is designed to generate a simple html file with _all_ of your Pinboard.in bookmarks The HTML file can be added to Launchbar's index as a custom bookmark file and you can search your entire Pinboard.in collection instantly from Launchbar (by title only). It includes any applied tags as part of the title to aid in searching. This does no checking for deltas, it just grabs the whole bunch and overwrites the html file every time. Don't run it too frequently. Set your username, password and the path/filename to write to below. =end ### User configuration PB_USERNAME = 'username' PB_PASSWORD = 'password' BOOKMARK_FILE = 'path/to/store/PinboardBookmarks.html' ### END config require 'cgi' require 'fileutils' require 'net/https' require 'rexml/document' class Net::HTTP alias_method :old_initialize, :initialize def initialize(*args) old_initialize(*args) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE end end def get_bookmarks xml = '' http = Net::HTTP.new('api.pinboard.in', 443) http.use_ssl = true http.start do |http| request = Net::HTTP::Get.new('/v1/posts/all') request.basic_auth PB_USERNAME,PB_PASSWORD response = http.request(request) response.value xml = response.body end return REXML::Document.new(xml) end def bookmarks_to_array(doc) bookmarks = [] doc.elements.each('posts/post') do |ele| post = {} ele.attributes.each {|key,val| post[key] = val; } bookmarks.push(post) end return bookmarks end bookmarks = bookmarks_to_array(get_bookmarks) output = "" bookmarks.each do |b| output += %Q{<a href="#{b['href']}" title="#{CGI.escapeHTML(b['extended']).gsub(/\n/,' ')}">#{b['description'].gsub(/\n+/,"\n")} @#{b['tag'].split(' ').join(' @')}</a>\n} end # Append to a file: open(File.expand_path(BOOKMARK_FILE), 'w') { |f| f.puts output }