Skip to content

Instantly share code, notes, and snippets.

@rhulha
Created February 12, 2015 02:20
Show Gist options
  • Save rhulha/92bee42c35c970cce761 to your computer and use it in GitHub Desktop.
Save rhulha/92bee42c35c970cce761 to your computer and use it in GitHub Desktop.
Wunderlist completed task remover written in Dart
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() {
var url = 'https://a.wunderlist.com/api/v1/';
var client_id = 'blabla';
var client = new http.Client();
client.post(url + "authenticate", body: {
"email": "bla@blabla.net",
"password": "blabla",
"client_id": client_id
}).then((response) {
var access_token = JSON.decode(response.body)['access_token'];
var headers = {
'X-Access-Token': access_token,
'X-Client-ID': client_id
};
//lists(client, url, headers); // use this to get the list id
deleteCompleted(client, url, headers, "142033354"); // insert the list id you wanna clean up here
});
//.whenComplete(client.close);;
}
void deleteCompleted(http.Client client, String url, Map headers, String list_id) {
client.get(url + "tasks?list_id=" + list_id + "&completed=true", headers: headers).then((response) {
List<String> tasks = JSON.decode(response.body);
for (var task in tasks) {
if (task['completed']) {
var delURL = url + "tasks/" + task['id'].toString() + "?revision=" + task['revision'].toString();
print(delURL);
client.delete(delURL, headers: headers).then((r) => print(r.body)).catchError((error) {
print('Something went wrong.');
print(error);
});
}
}
});
}
void lists(http.Client client, String url, Map headers) {
client.get(url + "lists", headers: headers).then((response) {
List<String> lists = JSON.decode(response.body);
for (var list in lists) {
print("${list['id']} | ${list['title']} | ${list['list_type']}");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment