Created
May 27, 2025 00:19
-
-
Save st3fan/27788cc5c84eeb85b9c594deb7d76001 to your computer and use it in GitHub Desktop.
Import your Pocket export into Instapaper
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 | |
# import-pocket-into-instapaper.py pocket/part_*.csv | |
import csv | |
import os | |
import sys | |
import time | |
import requests | |
def add_url_to_instapaper(*, username: str, password: str, url: str, title: str) -> int: | |
data = {"url": url} | |
if title != "" and url != title: | |
data["title"] = title | |
r = requests.post( | |
"https://www.instapaper.com/api/add", auth=(username, password), data=data | |
) | |
return r.status_code | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
raise SystemExit("usage: import-pocket-to-instapaper.py export.csv...") | |
if not (username := os.getenv("INSTAPAPER_USERNAME")): | |
raise SystemExit("error: missing INSTAPAPER_USERNAME") | |
if not (password := os.getenv("INSTAPAPER_PASSWORD")): | |
raise SystemExit("error: missing INSTAPAPER_PASSWORD") | |
with open(sys.argv[1], newline="") as csvfile: | |
reader = csv.reader(csvfile) | |
for idx, row in enumerate(reader): | |
if idx > 1: | |
print(f"{idx - 1} {row[1]}") | |
status = add_url_to_instapaper( | |
username=username, | |
password=password, | |
url=row[1], | |
title=row[0], | |
) | |
print(f" ==> {status}") | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment