Skip to content

Instantly share code, notes, and snippets.

@davekonopka
Last active January 3, 2023 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davekonopka/0dde9624166af6e65ffc09e1021c38ba to your computer and use it in GitHub Desktop.
Save davekonopka/0dde9624166af6e65ffc09e1021c38ba to your computer and use it in GitHub Desktop.
Readwise Reader CVS Import
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))
@davekonopka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment