Created
August 24, 2016 23:09
-
-
Save alexgarel/722c7798b608617f1d0f4c3e9dc11da0 to your computer and use it in GitHub Desktop.
Transform a delicious export to a RIS file, that can be imported in Zotero
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
#!/usr/bin/env python3 | |
"""Transform a delicious export to a RIS file, that can be imported in Zotero | |
You'll need lxml installed (python3-lxml) | |
""" | |
import datetime | |
import sys | |
from lxml import html | |
fname = sys.argv[1] | |
tree = html.parse(fname) | |
for l in tree.xpath(".//dl/dt"): | |
link = l[0] | |
url = link.attrib["href"] | |
text_date = link.attrib["add_date"] | |
try: | |
add_date = datetime.datetime.fromtimestamp(float(text_date)) | |
except ValueError: | |
add_date = None | |
tags = link.attrib["tags"].split(",") | |
title = link.text | |
desc_element = l.getnext() | |
desc = desc_element.text if desc_element is not None and desc_element.tag == "dd" else None | |
print("TY - GEN") | |
print("TI - " + title) | |
if desc: | |
print("AB - " + desc.strip("\n")) | |
if add_date is not None: | |
print("DA - " + add_date.strftime("%Y/%m/%d")) | |
print("UR - " + url) | |
for t in tags: | |
print("KW - " + t) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment