Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Synchronize recent pinboard bookmarks to delicious.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from lxml import etree
from StringIO import StringIO
import time
import os
import urllib
PINBOARD_USER = "username"
PINBOARD_PASS = "password"
DELICIOUS_USER = "username"
DELICIOUS_PASS = "password"
PINBOARD_CMD = "curl --silent https://%s:%s@api.pinboard.in/v1/posts/recent?count=100" % (PINBOARD_USER, PINBOARD_PASS)
DELICIOUS_CMD = "curl --silent https://%s:%s@api.del.icio.us/v1/posts/recent" % (DELICIOUS_USER, DELICIOUS_PASS)
def build_add_url(item):
result = "https://%s:%s@api.del.icio.us/v1/posts/add?" % (DELICIOUS_USER, DELICIOUS_PASS)
args = {'url' : item.get("href").encode("utf-8"),
'description' : item.get("description").encode("utf-8")}
if item.get("tag"):
args["tags"] = ",".join(item.get("tag").encode("utf-8").split(" "))
if item.get("time"):
args["dt"] = item.get("time")
if item.get("extended"):
args['extended'] = item.get("extended").encode("utf-8")
if item.get("shared"):
args['shared'] = item.get("shared")
return result + urllib.urlencode(args)
delicious_recent = os.popen(DELICIOUS_CMD).read()
pinboard_recent = os.popen(PINBOARD_CMD).read()
drxml = etree.parse(StringIO(delicious_recent))
prxml = etree.parse(StringIO(pinboard_recent))
last_item = drxml.findall("//post")[0]
for item in prxml.findall("//post"):
if item.get("hash") != last_item.get("hash"):
print "posting", build_add_url(item)
os.system("""curl --silent "%s" """ % build_add_url(item))
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment