Skip to content

Instantly share code, notes, and snippets.

@gameame
Created September 15, 2015 12:43
Show Gist options
  • Save gameame/9e4138e95037bbbd6ae0 to your computer and use it in GitHub Desktop.
Save gameame/9e4138e95037bbbd6ae0 to your computer and use it in GitHub Desktop.
Converts Kippt json export to Unmark json format
"""
This script converts Kippt json export to unmark json format.
Lists in Kippt will be converted to tags.
Bonus: lines in notes staring with 'Tags: ' will be imported as tags.
Required packages: pytz, tzlocal, python-dateutil
Usage:
python kippt_to_unmark.py export_data.json > export.json
"""
import json
import re
import sys
import dateutil.parser
import tzlocal
if __name__ == "__main__":
if len(sys.argv) != 2:
exit("Usage: python kippt_to_unmark.py export_data.json")
with open(sys.argv[1], "r") as kippt_file:
kippt_data = json.loads(kippt_file.read())
marks = []
for lizt in kippt_data['lists']:
for mark in lizt['links']:
# convert date to local timezone
created = dateutil.parser.parse(mark['created'])
created = created.astimezone(tzlocal.get_localzone())
notes = mark.get('notes', '')
tags = set([lizt['title']])
tag_str = re.match(r'^Tags: (.*)$', notes, re.MULTILINE)
if tag_str is not None:
tags.update(tag_str.group(1).split(", "))
notes += u"\n" + u" ".join([u"#" + tag for tag in tags])
marks.append({
'title': mark['title'],
'active': '1',
'created_on': "{created:%Y-%m-%d %H:%M:%S}".format(created=created),
'notes': notes,
'url': mark['url'],
})
# each mark must be on its own row
print """
{{
"export": {{
"export_version": 1,
"marks_count": {marks_count},
"marks": [
{marks}
]
}}
}}
""".format(marks_count=len(marks), marks=u",\n".join([json.dumps(mark) for mark in marks]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment