Created
January 29, 2017 17:18
-
-
Save ringods/bedde975e6e92a77e2321487ba45f313 to your computer and use it in GitHub Desktop.
Pinboard Import Script
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 characters
import csv | |
import json | |
import urllib | |
bookmark_file = '<bookmark_file_from_delicious>' | |
pinboard_token = '<your pinboard token>' | |
def process_tags(csv_tags): | |
json_tags = json.loads('{ "tags": %s }' % csv_tags) | |
json_tags = json_tags['tags'] | |
tags = [] | |
for json_tag in json_tags: | |
tags.append(unicode(json_tag['tag']).encode('utf-8')) | |
return tags | |
with open(bookmark_file, 'rb') as csvfile: | |
bookmarks = csv.reader(csvfile, delimiter=',', quotechar='"') | |
next(bookmarks) # Skip header | |
for bookmark in bookmarks: | |
bookmark_post_data = { | |
'url': bookmark[1], | |
'description': bookmark[0] | |
} | |
if bookmark[3]!='null': | |
bookmark_post_data['extended'] = bookmark[3] | |
tags = process_tags(bookmark[2]) | |
if len(bookmark[2]) > 0: | |
bookmark_post_data['tags'] = ",".join(tags) | |
bookmark_post_data['auth_token'] = pinboard_token | |
params = urllib.urlencode(bookmark_post_data) | |
print "Adding %s" % bookmark[1] | |
f = urllib.urlopen("https://api.pinboard.in/v1/posts/add?%s" % params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment