Created
October 21, 2015 19:52
-
-
Save tomasv/24ce8c3d9f83483deb85 to your computer and use it in GitHub Desktop.
Export all of your Wunderlist lists into simple Markdown checklists
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
#!/usr/bin/env ruby | |
# | |
# Usage: CLIENT_ID=a20f20 AUTH_TOKEN=a765q675dsf675 ruby wunderdown.rb | |
require 'json' | |
require 'restclient' | |
class Client | |
def initialize(client_id, access_token) | |
@access_token = access_token | |
@client_id = client_id | |
end | |
def get(path, params = {}) | |
JSON.parse( | |
RestClient.get( | |
api_root + path, | |
params: params, | |
'X-Access-Token' => @access_token, | |
'X-Client-ID' => @client_id | |
) | |
) | |
end | |
private | |
def api_root | |
'https://a.wunderlist.com/api/v1/' | |
end | |
end | |
client = Client.new(ENV['CLIENT_ID'], ENV['AUTH_TOKEN']) | |
class Wunderdown | |
def initialize(client) | |
@client = client | |
end | |
def lists | |
@client.get('lists') | |
end | |
def list_by_title(title) | |
lists.find { |list| list['title'] == title } | |
end | |
def full_tasks(list_id) | |
all_subtasks = @client.get('subtasks', list_id: list_id) | |
all_subtask_positions = @client.get('subtask_positions', list_id: list_id) | |
all_task_comments = @client.get('task_comments', list_id: list_id) | |
all_notes = @client.get('notes', list_id: list_id) | |
full_tasks = ordered_tasks(list_id).map { |task| | |
for_task_id = -> list { list.select { |i| i['task_id'] == task['id'] } } | |
subtask_positions = for_task_id.(all_subtask_positions).first | |
subtasks = for_task_id.(all_subtasks) | |
task_comments = for_task_id.(all_task_comments) | |
notes = for_task_id.(all_notes) | |
{ | |
task: task, | |
subtasks: ordered(subtasks, subtask_positions), | |
task_comments: task_comments, | |
notes: notes, | |
} | |
} | |
end | |
def ordered_tasks(list_id) | |
tasks = @client.get('tasks', list_id: list_id) | |
task_positions = @client.get('task_positions', list_id: list_id).first | |
ordered(tasks, task_positions) | |
end | |
private | |
def ordered(list, positions) | |
values = positions['values'] | |
list.sort_by { |item| values.index(item['id']).to_i }.reverse | |
end | |
end | |
wd = Wunderdown.new(client) | |
wd.lists.each do |list| | |
puts "# #{list['title']}" | |
puts | |
full_tasks = wd.full_tasks(list['id']) | |
full_tasks.each do |task| | |
check_mark = task[:task]['completed'] ? 'x' : ' ' | |
puts "- [#{check_mark}] #{task[:task]['title']}" | |
if task[:subtasks].any? | |
task[:subtasks].each do |subtask| | |
title = subtask['title'] | |
check_mark = subtask['completed'] ? 'x' : ' ' | |
puts " - [#{check_mark}] #{title}" | |
end | |
end | |
if task[:notes].any? | |
lines = task[:notes].flat_map { |note| note['content'].lines.map(&:chomp) } | |
lines.each { |line| puts " #{line}" } | |
puts | |
end | |
if task[:task_comments].any? | |
puts "### Comments" | |
task[:task_comments].each do |comment| | |
first_line, *lines = comment['text'].lines.map(&:chomp) | |
puts " * #{first_line}" | |
lines.each { |line| puts " #{line}" } | |
end | |
end | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You do need to set up an app to get the client ID and an auth token. :)
Prerequisites: