Published on

Simple reading management with Wunderlist

tl;dr

Add books to certain list in Wunderlist, mark as done when finished reading, and retrieve completed tasks via API if you want to make list of the books you've read.

  • Register dummy app, and get client_id and access_token on Wunderlist's developer's page
  • Create list called "Reading"
  • Get some books
  • Add task like Author Name, Title, ...
  • Reading time
    • Write impressions or quote interesting part of the book, and put them into comments form in Wunderlist
  • Mark as done when finished or just got bored
  • Retrieve list via API
    • Filter by keys such as completed_at, created_at if you want...
  • Write article about books I've read

Script (Python 3.5)

#!/usr/bin/env python3
from requests_oauthlib import OAuth2Session
import json
import sys
from typing import Dict


def req_get(s: OAuth2Session, url: str, params: Dict=None):
    got = s.get(url, params=params)
    if got.status_code == 200:
        results = json.loads(got.text)
        return results
    else:
        sys.stderr.write("HTTP Error: {}".format(got.status_code))
        return {}


def get_id_of_list(lists: Dict, name: str):
    for d in lists:
        if d['title'] == name:
            return d['id']
    return None


if __name__ == '__main__':
    client_id = sys.argv[1]
    access_token = sys.argv[2]
    api_url = "https://a.wunderlist.com/api/v1/"

    session = OAuth2Session()
    session.headers['X-Client-ID'] = client_id
    session.headers['X-Access-Token'] = access_token
    lists = req_get(session, api_url+"lists")
    reading_list_id = get_id_of_list(lists, 'Reading')

    if reading_list_id:
        params = {'completed': True, 'list_id': reading_list_id}
        books = req_get(session, api_url+"tasks", params)
        for book in sorted(books, key=lambda x: x['completed_at']):
            # Write to stdout as markdown's numbered list formatting
            print("1. " + book['title'])