links thing:Migrate Pinboard data

This is the Python program I used to migrate the JSON export from Pinboard into a CSV file to be imported into MediaWiki using the Data Transfer extension.

This created and was imported with Category:Imported from Pinboard.

import json import csv import time from datetime import datetime from pytz import timezone

json_data=open('pinboard.json') pins=json.loads(json_data.read)

f=csv.writer(open("output.csv","wb+"))

f.writerow(["Title", "Bookmark[URL]", "Bookmark[Title]", "Bookmark[Created date]", "Bookmark[Starred]", "Bookmark[Unread]", "Bookmark[Excerpt]", "Bookmark[Tag]", "Bookmark[Created by]", "Free Text"])
 * 1) Write CSV Header, If you dont need that, remove this line

for x in pins: out_title = x["description"].encode('ascii', 'ignore').strip out_title = out_title.replace('"',)   out_title = out_title.replace('|',)    out_title = out_title.replace('~',)    out_title = out_title.replace('/',)    out_title = out_title.replace('!',)    out_title = out_title.replace('*',)    out_title = out_title.replace('#','-')    out_title = out_title.replace('<','-')    out_title = out_title.replace('>','-')    out_title = out_title.replace('[','-')    out_title = out_title.replace(']','-')    out_title = out_title.replace('{','-')    out_title = out_title.replace('}','-')    out_url = x["href"].encode('ascii', 'ignore').strip    out_time = x["time"]    the_time = datetime.strptime(out_time, "%Y-%m-%dT%H:%M:%SZ")    the_time = the_time.replace(tzinfo=timezone('UTC'))    local_time = the_time.astimezone(timezone('US/Central'))    final_time = local_time.strftime("%B %d, %Y %I:%M:%S %p")    out_unread = x["toread"].title    out_starred = "No" out_created_by = "Thingles" out_free_text = "" out_tags = x["tags"].encode('ascii', 'ignore').strip.title out_tags_arr = out_tags.split for i in range(len(out_tags_arr)): out_tags_arr[i] = out_tags_arr[i].replace('_', ' ') final_tags = ', '.join(out_tags_arr) out_excerpt = x["extended"].encode('ascii', 'ignore').strip print "Writing " + out_title f.writerow([out_title, out_url, out_title, final_time, out_starred, out_unread, out_excerpt, final_tags, out_created_by, out_free_text])