Last active
January 3, 2023 16:01
-
-
Save davekonopka/0dde9624166af6e65ffc09e1021c38ba to your computer and use it in GitHub Desktop.
Readwise Reader CVS Import
This file contains 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
import csv | |
import requests | |
import time | |
filename = 'PathToYourExportFile.csv' | |
with open(filename, 'r') as csvfile: | |
datareader = csv.reader(csvfile) | |
line = 1 | |
entries = list(datareader) | |
while True: | |
if line >= len(entries): | |
break | |
req = requests.post( | |
url="https://readwise.io/api/v3/save/", | |
headers={ | |
"Authorization": "Token XXX"}, | |
json={ | |
"url": entries[line][6], | |
"tags": ["some-tag"], | |
"location": "new", | |
"title": entries[line][0] | |
} | |
) | |
waitSeconds = req.headers.get('Retry-After', "0") | |
if req.status_code == 201: | |
print(f'{req.status_code} Article imported...') | |
line += 1 | |
elif req.status_code == 200: | |
print(f'{req.status_code} Article already imported...') | |
line += 1 | |
elif req.status_code == 429: | |
print(f'{req.status_code} Waiting {waitSeconds}s for rate limiting...') | |
time.sleep(int(waitSeconds)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reader API reference