-
-
Save iwinux/4531202 to your computer and use it in GitHub Desktop.
# encoding: utf-8 | |
from __future__ import print_function | |
from json import dumps as to_json | |
from datetime import datetime, timedelta | |
import requests | |
URL_BASE="https://i.doit.im/tasks/%s" | |
DOIT_BOXES = ('inbox', 'today', 'next', 'tomorrow', 'scheduled', 'someday', 'waiting') | |
COOKIES = { 'autologin': 'Your Autologin Cookie Here' } | |
PROJECT_TRANS = { 'Project Name With Space': 'ProjectNameWithoutSpace' } | |
TAG_TRANS = { 'TagBefore': 'TagAfter' } | |
PRIORITY_TRANS = ('', 'L', 'M', 'H') | |
TIME_OFFSET = timedelta(hours=8) | |
def fetch_doit_items(): return sum(map(fetch_doit_box, DOIT_BOXES), []) | |
def fetch_doit_box(path): return requests.get(URL_BASE % path, cookies=COOKIES).json['entities'] | |
def doit2task(item): | |
created_at = trans_time(item['created']) | |
task = { | |
'description': item['title'], | |
'status': 'pending', | |
'uuid': item['uuid'], | |
'entry': created_at | |
} | |
if item['start_at'] > 0: | |
task['due'] = trans_time(item['start_at']) | |
if item['priority'] > 0: | |
task['priority'] = PRIORITY_TRANS[item['priority']] | |
if item['project_name']: | |
task['project'] = trans_project_name(item['project_name']) | |
if item['tags']: | |
task['tags'] = trans_tags(item['tags']) | |
if item['notes']: | |
task['annotations'] = [{ 'entry': created_at, 'description': item['notes'] }] | |
return task | |
def trans_project_name(name): return PROJECT_TRANS.get(name, None) or name | |
def trans_tags(tags): return map(lambda tag: TAG_TRANS.get(tag, None) or tag, tags) | |
def trans_time(value): | |
time = datetime.fromtimestamp(value / 1000) - TIME_OFFSET | |
return '%sZ' % time.isoformat().replace('-', '').replace(':', '') | |
if __name__ == '__main__': | |
items = fetch_doit_items() | |
for item in items: | |
task = doit2task(item) | |
print(to_json(task, ensure_ascii=False).encode('utf-8'), '\n') |
BACKUP YOUR DATA BEFORE TRYING
Hi!
I cannot seem to get this script to work. When run, I observe the following error messages (I renamed the script to doit.im-export.py). This is under Ubuntu 12.04, with the python-requests package installed:
from: too many arguments
from: too many arguments
from: too many arguments
./doit.im-export.py: line 9: syntax error near unexpected token `('
./doit.im-export.py: line 9: `DOIT_BOXES = ('inbox', 'today', 'next', 'tomorrow', 'scheduled', 'someday', 'waiting')'
When I run it, my cursor changes to a double-cross-hairs icon, after the three "from: too many arguments" lines are printed. I suspect this has to do with obtaining the autologin cookie, but I am just guessing on this. I tried just clicking on my terminal windows, and the script then seemed to generate a "requests" file in the same directory as the script, and it was a Postscript file. I converted to PDF and viewed it, and it was a screenshot of my terminal window. Thus my guess that this has to do with authentication, that is, that perhaps I am supposed to click an open Doit.im tab within Firefox or Chrome.
More generally, it's just not clear how one is supposed to use this script. I see a time delta variable, and a variable for declaring my autologin cookie, but I have no idea how to obtain that. If someone could offer a little more documentation (e.g., a README.md), I'd be most grateful, as I am eager to routinely backup my Doit.im data. Longer-term, I am very seriously considering switching to TaskWarrior, as the collaborative features of Doit.im are still much weaker than I hoped they would have evolved. If I'm going to use a GTD tool for just myself, TaskWarrior seems a lot more powerful, and its CLI-only interface allows for much faster edits and updates I would imagine.
Thanks!
Doug
You need to install the
requests
package first:sudo pip install requests
.