{"id":73,"date":"2019-01-12T21:07:28","date_gmt":"2019-01-12T21:07:28","guid":{"rendered":"http:\/\/api.intelligentonlinetools.com\/diy\/?p=73"},"modified":"2019-01-17T02:25:32","modified_gmt":"2019-01-17T02:25:32","slug":"python-api-example-wallabag-web-application-extracting-entries-quotes","status":"publish","type":"post","link":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/","title":{"rendered":"Python API Example with Wallabag Web Application for Extracting Entries and Quotes"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/12\/python-and-wallabag.png\" alt=\"python and wallabag\" width=\"404\" height=\"215\" class=\"aligncenter size-full wp-image-62\" srcset=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/12\/python-and-wallabag.png 404w, http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/12\/python-and-wallabag-300x160.png 300w\" sizes=\"(max-width: 404px) 100vw, 404px\" \/><\/p>\n<p>In the previous post <a href=\"https:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application\/\" target=\"_blank\">Python API Example with Wallabag Web Application<\/a> we explored how to connect via Web API to Wallabag and make entry to Wallabag  web application. For this we setup API, obtained token via python script and then created entry (added link).<\/p>\n<p>In this post we will extract <b>entries<\/b> through Web API with python script. From entry we will extract needed information such as id of entry.  Then for this id we will look how to extract <b>annotations and quotes<\/b>.<\/p>\n<p><b>Wallabag<\/b> is read it later web application like Pocket or Instapaper. Quotes are some texts that we highlight within Wallabag. Annotations are our notes that we can save together with annotations. For one entry we can have several quotes \/ annotations. Wallabag is open source software so you can download it and install it locally or remotely on web server.<\/p>\n<p>If you did not setup API you need first setup API to run code below. See previous post how to do this.<br \/>\nThe beginning of script should be also same as before &#8211; as we need first provide our credentials and obtain token. <\/p>\n<h2>Obtaining Entries<\/h2>\n<p>After obtaining token we move to actual downloading data. We can obtain entries using below code:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\np = {'archive': 0 , 'starred': 0, 'access_token': access}\r\nr = requests.get('{}\/api\/entries.txt'.format(HOST), p)\r\n<\/pre>\n<p>p is holding parameters that allow to limit our output.<br \/>\nThe return data is json structure with a lot of information including entries. It does not include all entries. It divides entries in set of 30 per page and it provides link to next page. So we can extract next page link and then extract entries again.<\/p>\n<p>Each entry has link, id and some other information. <\/p>\n<h2>Obtaining Annotations \/ Quotes <\/h2>\n<p>To extract annotations, quotes we can use this code:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\np = {'access_token': access}\r\nlink = '{}\/api\/annotations\/' + str(data['_embedded']['items'][3]['id']) + '.txt'\r\nprint (link)\r\nr = requests.get(link.format(HOST), p)\r\ndata=json.loads(r.text)\r\n<\/pre>\n<h2>Full Python Source Code<\/h2>\n<p>Below is full script example: <\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# Extract entries using wallabag API and Python\r\n# Extract quotes and annotations for specific entry\r\n# Save information to files\r\nimport requests\r\nimport json\r\n\r\n# only these 5 variables have to be set\r\n#HOST = 'https:\/\/wallabag.example.org'\r\nUSERNAME = 'xxxxxx'\r\nPASSWORD = 'xxxxxx'\r\nCLIENTID = 'xxxxxxxxxxxx'\r\nSECRET = 'xxxxxxxxxxx'\r\nHOST = 'https:\/\/intelligentonlinetools.com\/wallabag\/web'    \r\n\r\n\r\ngettoken = {'username': USERNAME, 'password': PASSWORD, 'client_id': CLIENTID, 'client_secret': SECRET, 'grant_type': 'password'}\r\nprint (gettoken)\r\n\r\nr = requests.post('{}\/oauth\/v2\/token'.format(HOST), gettoken)\r\nprint (r.content)\r\n\r\n\r\naccess = r.json().get('access_token')\r\n\r\np = {'archive': 0 , 'starred': 0, 'access_token': access}\r\nr = requests.get('{}\/api\/entries.txt'.format(HOST), p)\r\n\r\ndata=json.loads(r.text)\r\nprint (type(data))\r\n\r\n\r\nwith open('data1.json', 'w') as f:  # writing JSON object\r\n      json.dump(data, f)\r\n\r\n\r\nfor key, value in data.items():\r\n     print (key, value)\r\n     \r\n#Below how to access needed information at page level like next link\r\n#and at entry level like id, url for specific 3rd entry (counting from 0)      \r\nprint (data['_links']['next']) \r\nprint (data['pages'])\r\nprint (data['page']) \r\nprint (data['_embedded']['items'][3]['id'])  \r\nprint (data['_embedded']['items'][3]['url'])  \r\nprint (data['_embedded']['items'][3]['annotations'])\r\n\r\n\r\np = {'access_token': access}\r\n\r\nlink = '{}\/api\/annotations\/' + str(data['_embedded']['items'][3]['id']) + '.txt'\r\nprint (link)\r\nr = requests.get(link.format(HOST), p)\r\ndata=json.loads(r.text)\r\nwith open('data2.json', 'w') as f:  # writing JSON object\r\n      json.dump(data, f)\r\n\r\n#Below how to access first and second annotation \/ quote\r\n#assuming they exist \r\nprint (data['rows'][0]['quote']) \r\nprint (data['rows'][0]['text']) \r\nprint (data['rows'][1]['quote'])    \r\nprint (data['rows'][1]['text'])\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>In this post we learned how to use Wallabag API to download entries, annotations and quotes. To do this we first downloaded entries and ids. Then we downloaded annotations and quotes for specific entry id. Additionally we learned some json python and json examples to get needed information from retrieved data. <\/p>\n<p>Feel free to provide feedback or ask related questions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post Python API Example with Wallabag Web Application we explored how to connect via Web API to Wallabag and make entry to Wallabag web application. For this we setup API, obtained token via python script and then created entry (added link). In this post we will extract entries through Web API with &#8230; <a title=\"Python API Example with Wallabag Web Application for Extracting Entries and Quotes\" class=\"read-more\" href=\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\" aria-label=\"More on Python API Example with Wallabag Web Application for Extracting Entries and Quotes\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false},"categories":[4,14],"tags":[5,18,15,6],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python\" \/>\n<meta property=\"og:description\" content=\"In the previous post Python API Example with Wallabag Web Application we explored how to connect via Web API to Wallabag and make entry to Wallabag web application. For this we setup API, obtained token via python script and then created entry (added link). In this post we will extract entries through Web API with ... Read more\" \/>\n<meta property=\"og:url\" content=\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\" \/>\n<meta property=\"og:site_name\" content=\"Using Web API with Python\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-12T21:07:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-17T02:25:32+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/12\/python-and-wallabag.png\" \/>\n<meta name=\"author\" content=\"owygs156\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"owygs156\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\",\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\",\"name\":\"Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python\",\"isPartOf\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#website\"},\"datePublished\":\"2019-01-12T21:07:28+00:00\",\"dateModified\":\"2019-01-17T02:25:32+00:00\",\"author\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332\"},\"breadcrumb\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/api.intelligentonlinetools.com\/diy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python API Example with Wallabag Web Application for Extracting Entries and Quotes\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#website\",\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/\",\"name\":\"Using Web API with Python\",\"description\":\"Using Web API with Python\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/api.intelligentonlinetools.com\/diy\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332\",\"name\":\"owygs156\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"caption\":\"owygs156\"},\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/author\/owygs156\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/","og_locale":"en_US","og_type":"article","og_title":"Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python","og_description":"In the previous post Python API Example with Wallabag Web Application we explored how to connect via Web API to Wallabag and make entry to Wallabag web application. For this we setup API, obtained token via python script and then created entry (added link). In this post we will extract entries through Web API with ... Read more","og_url":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/","og_site_name":"Using Web API with Python","article_published_time":"2019-01-12T21:07:28+00:00","article_modified_time":"2019-01-17T02:25:32+00:00","og_image":[{"url":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/12\/python-and-wallabag.png"}],"author":"owygs156","twitter_card":"summary_large_image","twitter_misc":{"Written by":"owygs156","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/","url":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/","name":"Python API Example with Wallabag Web Application for Extracting Entries and Quotes - Using Web API with Python","isPartOf":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#website"},"datePublished":"2019-01-12T21:07:28+00:00","dateModified":"2019-01-17T02:25:32+00:00","author":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332"},"breadcrumb":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/python-api-example-wallabag-web-application-extracting-entries-quotes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/api.intelligentonlinetools.com\/diy\/"},{"@type":"ListItem","position":2,"name":"Python API Example with Wallabag Web Application for Extracting Entries and Quotes"}]},{"@type":"WebSite","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#website","url":"http:\/\/api.intelligentonlinetools.com\/diy\/","name":"Using Web API with Python","description":"Using Web API with Python","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/api.intelligentonlinetools.com\/diy\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332","name":"owygs156","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","caption":"owygs156"},"url":"http:\/\/api.intelligentonlinetools.com\/diy\/author\/owygs156\/"}]}},"_links":{"self":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":7,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":83,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/73\/revisions\/83"}],"wp:attachment":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}