Readwise API usage
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'Correct token'" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import datetime\n", | |
"import requests\n", | |
"import os\n", | |
"TOKEN=os.environ[\"READWISE\"]\n", | |
"\n", | |
"response = requests.get(\n", | |
" url=\"https://readwise.io/api/v2/auth/\",\n", | |
" headers={\"Authorization\": f\"Token {TOKEN}\"},\n", | |
")\n", | |
"\n", | |
"\"Correct token\" if response.status_code == 204 else \"Incorrect token\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'count': 7,\n", | |
" 'next': None,\n", | |
" 'previous': None,\n", | |
" 'results': [{'id': 4625724,\n", | |
" 'title': 'Douglas R. Hofstadter - Gödel, Escher, Bach_ an Eternal Golden Braid-Basic Books',\n", | |
" 'author': '1994',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 6,\n", | |
" 'last_highlight_at': '2020-09-14T13:09:37Z',\n", | |
" 'updated': '2020-09-14T18:05:29.023564Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-2.dae1dc4d332b.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625724'},\n", | |
" {'id': 4625723,\n", | |
" 'title': 'Matt Ridley',\n", | |
" 'author': 'The Red Queen',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 45,\n", | |
" 'last_highlight_at': '2020-09-09T12:06:28Z',\n", | |
" 'updated': '2020-09-14T18:05:28.968661Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-0.c6917d331b03.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625723'},\n", | |
" {'id': 4625722,\n", | |
" 'title': 'Frederick P. Brooks - The Design of Design_ Essays From a Computer Scientist-Addison-Wesley Professional',\n", | |
" 'author': '2010',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 2,\n", | |
" 'last_highlight_at': '2020-05-18T18:32:19Z',\n", | |
" 'updated': '2020-09-14T18:05:28.914585Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-0.c6917d331b03.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625722'},\n", | |
" {'id': 4625721,\n", | |
" 'title': 'Seneca - Letters From a Stoic',\n", | |
" 'author': 'Penguin, 1969',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 29,\n", | |
" 'last_highlight_at': '2020-06-11T12:51:54Z',\n", | |
" 'updated': '2020-09-14T18:05:28.851049Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-2.dae1dc4d332b.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625721'},\n", | |
" {'id': 4625720,\n", | |
" 'title': 'Richard Dawkins - The Selfish Gene',\n", | |
" 'author': '2006, Oxford University Press, USA',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 22,\n", | |
" 'last_highlight_at': '2020-06-01T13:28:16Z',\n", | |
" 'updated': '2020-09-14T18:05:28.797098Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-0.c6917d331b03.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625720'},\n", | |
" {'id': 4625719,\n", | |
" 'title': 'Martin Kleppmann Designing Data-Intensive Applications',\n", | |
" 'author': '2017',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 12,\n", | |
" 'last_highlight_at': '2020-05-13T20:11:00Z',\n", | |
" 'updated': '2020-09-14T18:05:28.737718Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-4.11327a2af05a.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625719'},\n", | |
" {'id': 4625718,\n", | |
" 'title': 'Thus Spake Zarathustra',\n", | |
" 'author': 'Friedrich Wilhelm Nietzsche',\n", | |
" 'category': 'books',\n", | |
" 'num_highlights': 17,\n", | |
" 'last_highlight_at': '2020-05-13T12:00:17Z',\n", | |
" 'updated': '2020-09-14T18:05:28.683424Z',\n", | |
" 'cover_image_url': 'https://readwise-assets.s3.amazonaws.com/static/images/default-book-icon-9.63dbe834380e.png',\n", | |
" 'highlights_url': 'https://readwise.io/bookreview/4625718'}]}" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# getting books that were updated last week\n", | |
"\n", | |
"delay = datetime.datetime.now() - datetime.timedelta(days=100)\n", | |
"\n", | |
"querystring = {\n", | |
" \"category\": \"books\",\n", | |
" \"updated__gt\": delay.strftime(\"%Y-%m-%dT%H:%M:%SZ\"),\n", | |
"}\n", | |
"\n", | |
"response = requests.get(\n", | |
" url=\"https://readwise.io/api/v2/books/\",\n", | |
" headers={\"Authorization\": f\"Token {TOKEN}\"},\n", | |
" params=querystring\n", | |
")\n", | |
"\n", | |
"data = response.json()\n", | |
"data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'count': 17,\n", | |
" 'next': None,\n", | |
" 'previous': None,\n", | |
" 'results': [{'id': 86575414,\n", | |
" 'text': '“He who climbeth on the highest mountains, laugheth at all tragic plays and tragic realities.”—ZARATHUSTRA,',\n", | |
" 'note': '',\n", | |
" 'location': 2121,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-05-13T12:00:17Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:22.727179Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575392,\n", | |
" 'text': 'Where is innocence? Where there is will to procreation. And he who seeketh to create beyond himself, hath for me the purest will.',\n", | |
" 'note': '',\n", | |
" 'location': 1777,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-27T02:23:44Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.609578Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575391,\n", | |
" 'text': 'Whatever cannot obey itself, is commanded. Such is the nature of living things.',\n", | |
" 'note': '',\n", | |
" 'location': 1661,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-25T11:31:31Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.563194Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575390,\n", | |
" 'text': 'It is more, verily, when out of one’s own burning cometh one’s own teaching!',\n", | |
" 'note': '',\n", | |
" 'location': 1375,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-24T11:41:19Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.518103Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575388,\n", | |
" 'text': 'The man of knowledge must be able not only to love his enemies, but also to hate his friends.',\n", | |
" 'note': '',\n", | |
" 'location': 1222,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-21T12:07:26Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.421995Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575387,\n", | |
" 'text': 'When, however, ye have an enemy, then return him not good for evil: for that would abash him. But prove that he hath done something good to you.',\n", | |
" 'note': '',\n", | |
" 'location': 1093,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-21T03:11:31Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.377724Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575386,\n", | |
" 'text': 'Two different things wanteth the true man: danger and diversion. Therefore wanteth he woman, as the most dangerous plaything.',\n", | |
" 'note': '',\n", | |
" 'location': 1065,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-21T03:05:18Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.332871Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575385,\n", | |
" 'text': 'Everything in woman is a riddle, and everything in woman hath one solution—it is called pregnancy.',\n", | |
" 'note': '',\n", | |
" 'location': 1064,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-21T03:04:52Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.288548Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575384,\n", | |
" 'text': '“He who seeketh may easily get lost himself. All isolation is wrong”: so say the herd. And long didst thou belong to the herd.',\n", | |
" 'note': '',\n", | |
" 'location': 1021,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-21T02:50:41Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.241759Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575383,\n", | |
" 'text': 'There are the spiritually consumptive ones: hardly are they born when they begin to die, and long for doctrines of lassitude and renunciation.',\n", | |
" 'note': '',\n", | |
" 'location': 797,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-19T12:44:26Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:21.194155Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575375,\n", | |
" 'text': 'What is heavy? so asketh the load-bearing spirit; then kneeleth it down like the',\n", | |
" 'note': '',\n", | |
" 'location': 545,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-16T12:27:01Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:20.709336Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575374,\n", | |
" 'text': 'how the spirit becometh a camel, the camel a lion, and the lion at last a child.',\n", | |
" 'note': '',\n", | |
" 'location': 543,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-16T12:26:27Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:20.658766Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575372,\n", | |
" 'text': 'one must still have chaos in one, to give birth to a dancing star.',\n", | |
" 'note': 'P',\n", | |
" 'location': 439,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-16T12:06:22Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:27.873428Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575371,\n", | |
" 'text': 'Man is a rope stretched between the animal and the Superman—a rope over an abyss.',\n", | |
" 'note': 'I',\n", | |
" 'location': 408,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-15T12:27:05Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:27.749459Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575370,\n", | |
" 'text': 'Altered is Zarathustra; a child hath Zarathustra become; an awakened one is Zarathustra: what wilt thou do in the land of the sleepers?',\n", | |
" 'note': 'O',\n", | |
" 'location': 360,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-15T12:05:00Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:27.626765Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575369,\n", | |
" 'text': '“The Greeks are interesting and extremely important because they reared such a vast number of great individuals.',\n", | |
" 'note': '',\n", | |
" 'location': 162,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-14T12:43:31Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:20.409994Z',\n", | |
" 'book_id': 4625718},\n", | |
" {'id': 86575368,\n", | |
" 'text': '“How can one praise and glorify a nation as a whole?—Even among the Greeks, it was the INDIVIDUALS that counted.”',\n", | |
" 'note': 'G',\n", | |
" 'location': 161,\n", | |
" 'location_type': 'location',\n", | |
" 'highlighted_at': '2020-04-14T12:40:16Z',\n", | |
" 'url': None,\n", | |
" 'color': '',\n", | |
" 'updated': '2020-09-14T18:05:27.505902Z',\n", | |
" 'book_id': 4625718}]}" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# getting highlights from a particular book\n", | |
"# made after February 1st, 2020, 21:35:53 UTC\n", | |
"querystring = {\n", | |
" \"book_id\": 4625718,\n", | |
" \"highlighted_at__gt\": \"2020-02-01T21:35:53Z\",\n", | |
"}\n", | |
"\n", | |
"response = requests.get(\n", | |
" url=\"https://readwise.io/api/v2/highlights/\",\n", | |
" headers={\"Authorization\": f\"Token {TOKEN}\"},\n", | |
" params=querystring\n", | |
")\n", | |
"\n", | |
"data = response.json()\n", | |
"data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment