Created
July 30, 2018 19:03
-
-
Save jaanus/3f5fc340c0f8a92f3ecc06dabcf38970 to your computer and use it in GitHub Desktop.
Upload Instapaper bookmarks to Pinboard. For input, uses the CSV file as exported from Instapaper, or received from their support.
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 | |
"""Upload Instapaper bookmarks to Pinboard. For input, uses the CSV file as | |
exported from Instapaper, or received from their support. | |
""" | |
import sys | |
import os | |
import argparse | |
import csv | |
# https://github.com/lionheart/pinboard.py | |
import pinboard | |
def main(arguments): | |
parser = argparse.ArgumentParser( | |
description=__doc__, | |
formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument('-i', '--infile', help="Input file in CSV format as exported from Instapaper", required=True, type=argparse.FileType('r')) | |
args = parser.parse_args(arguments) | |
try: | |
api_token = os.environ["PINBOARD_TOKEN"] | |
except KeyError: | |
print("You must specify Pinboard API token in PINBOARD_TOKEN environment variable.") | |
return 1 | |
pb = pinboard.Pinboard(api_token) | |
reader = csv.reader(args.infile, delimiter=',', quotechar="\"") | |
next(reader) # skip 1st line (header) | |
for row in reader: | |
# sometimes title is blank. Pinboard API will barf and abort on this. I prefer to just fix the CSV manually in that case | |
url, title, selection, folder = row | |
print(folder, " – ", title) | |
toread = False | |
# Pinboard doesn’t like multi-word folders and converts them to multiple tags. I had few enough of these | |
# that I could just fix that manually. | |
tags = [folder] | |
if folder == "Unread": | |
toread = True | |
tags = [] | |
pb.posts.add(url=url, description=title, extended=selection, tags=tags, toread = toread) | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just in case someone is reading this in 2024, I have used this script as the basis to get my Instapaper links to Pinboard. But I had to make some changes because the exported CSV is now in a different format, which made the script crash.
I've also added a new feature where it uses GPT to summarize the webpage. I found this helpful to use when the Instapaper link itself doesn't have a title or a description. It's commented out, but please don't hesitate to use it.
Furthermore, I would rather not use
.env
for this small little script that I run once, i.e., the API keys are hard-coded. I hope this is understandable.