Skip to content

Commit 4fac240

Browse files
This is a squash of 8 commits:
This is a squash of 4 commits: Update README.md. Remove imports that aren't used and cause problems. Partially fix sync. Todoist -> Habitica sync appears to kind of work. Update README.md. Add more dependencies that are needed for installation. Fix path to be more accurate. Fix bug. Clean-up comments and remove some debugging code. Update README.md Save work on refactor. Begin to integrate replacement library. Fix some lines of code. Uncomment most lines of code. Remove some dead code. Further integrate api.
1 parent 07b72ce commit 4fac240

File tree

7 files changed

+190
-98
lines changed

7 files changed

+190
-98
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ That means that if you create a task in Todoist and then check it off, right now
1313

1414
## INSTALLATION
1515

16-
There are two dependencies you'll need to install, and the commands to install them are as follows:
16+
There are a number dependencies you'll need to install, and the commands to install them are as follows:
1717
```
1818
pip install todoist-python
1919
pip install requests
20+
pip install scriptabit
21+
pip install tzlocal
22+
pip install iso8601
23+
pip install python-dateutil
2024
```
2125
Finally, you need to add your API tokens to the `Habitica-Plus-Todoist/source/auth.cfg.example` file. You can find your Habitica API User ID and API key by visiting https://habitica.com/user/settings/api while logged in, and your Todoist API token can be found by visiting https://todoist.com/prefs/integrations while logged in. Once you've added these tokens, you should rename the file to `Habitica-Plus-Todoist/source/auth.cfg` (remove the '.example' at the end).
2226

@@ -35,7 +39,7 @@ If you'd like to change how the sync interprets difficulty or priority, please e
3539

3640
## USAGE
3741

38-
Try running `python source/oneWaySync.py` in your terminal.
42+
Try running `python oneWaySync.py` in your terminal. (You have to run the command from the same directory that auth.cfg exists in).
3943

4044
## Credit
4145

habiticaTodo/config.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'''This file deals with config related functions'''
2+
import logging
3+
import configparser
4+
5+
def getTodoistToken(configfile):
6+
logging.debug('Loading todoist auth data from %s' % configfile)
7+
8+
try:
9+
cf = open(configfile)
10+
except IOError:
11+
logging.error("Unable to find '%s'." % configfile)
12+
exit(1)
13+
14+
config = configparser.SafeConfigParser()
15+
config.readfp(cf)
16+
17+
cf.close()
18+
19+
# Get data from config
20+
try:
21+
tt = config.get('Todoist', 'api-token')
22+
23+
except configparser.NoSectionError:
24+
logging.error("No 'Todoist' section in '%s'" % configfile)
25+
exit(1)
26+
27+
except configparser.NoOptionError as e:
28+
logging.error("Missing option in auth file '%s': %s" % (configfile, e.message))
29+
exit(1)
30+
31+
return tt
32+
33+
def get_started(configfile):
34+
"""Get Habitica authentication data from the AUTH_CONF file."""
35+
36+
logging.debug('Loading habitica auth data from %s' % configfile)
37+
38+
try:
39+
cf = open(configfile)
40+
except IOError:
41+
logging.error("Unable to find '%s'." % configfile)
42+
exit(1)
43+
44+
config = configparser.SafeConfigParser()
45+
config.readfp(cf)
46+
47+
cf.close()
48+
49+
# Get data from config
50+
rv = {}
51+
try:
52+
rv = {'url': config.get('Habitica', 'url'),
53+
'x-api-user': config.get('Habitica', 'login'),
54+
'x-api-key': config.get('Habitica', 'password')}
55+
56+
except configparser.NoSectionError:
57+
logging.error("No 'Habitica' section in '%s'" % configfile)
58+
exit(1)
59+
60+
except configparser.NoOptionError as e:
61+
logging.error("Missing option in auth file '%s': %s"
62+
% (configfile, e.message))
63+
exit(1)
64+
65+
# Return auth data as a dictionnary
66+
return rv

habiticaTodo/habitica.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''Habitica related functions'''
2+
import requests
3+
from hab_task import HabTask
4+
5+
def get_all_habtasks(auth):
6+
#Todoist tasks are, I think, classes. Let's make Habitica tasks classes, too.
7+
url = 'https://habitica.com/api/v3/tasks/user/'
8+
response = requests.get(url,headers=auth)
9+
hab_raw = response.json()
10+
hab_tasklist = hab_raw['data'] #FINALLY getting something I can work with... this will be a list of dicts I want to turn into a list of objects with class hab_tasks. Hrm. Weeeelll, if I make a class elsewhere....
11+
12+
#keeping records of all our tasks
13+
hab_tasks = []
14+
15+
#No habits right now, I'm afraid, in hab_tasks--Todoist gets upset. So we're going to make a list of dailies and todos instead...
16+
for task in hab_tasklist:
17+
item = HabTask(task)
18+
if item.category == 'reward':
19+
pass
20+
elif item.category == 'habit':
21+
pass
22+
else:
23+
hab_tasks.append(item)
24+
return(hab_tasks, response)

scripts/runHabitica-todo.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
# Run habiticaTodo, avoid proxy.
3+
unset http_proxy
4+
unset https_proxy
5+
6+
pwd
7+
cd habiticaTodo
8+
python3.9 oneWaySync.py

source/main.py

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
"""
66

77
"""Here's where we import stuff we need..."""
8-
import todoist
8+
#import todoist
99
import requests
1010
import json
1111
from hab_task import HabTask
1212
from todo_task import TodTask
1313
import os
1414
import logging
15-
try:
16-
import ConfigParser as configparser
17-
except:
18-
import configparser
15+
import configparser
1916

2017
from datetime import datetime
21-
from dateutil import parser
18+
#from dateutil import parser
2219
import re
2320

2421

@@ -132,7 +129,7 @@ def check_matchDict(matchDict):
132129
print("something is weird check tod %s" % t)
133130

134131
def check_newMatches(matchDict,tod_uniq,hab_uniq):
135-
from main import add_hab_id, make_tod_from_hab
132+
#from main import add_hab_id
136133
matchesHab = []
137134
matchesTod = []
138135
for tod in tod_uniq:
@@ -272,18 +269,17 @@ def get_uniqs(matchDict,tod_tasks,hab_tasks):
272269

273270
for tod in tod_tasks:
274271
tid = tod.id
275-
if tod.complete == 0:
272+
if tod.is_completed:
276273
if tid not in matchDict.keys():
277274
tod_uniq.append(tod)
278275

279276
for hab in hab_tasks:
280277
tid = hab.alias
281278
if tid not in matchDict.keys():
282-
print(tid)
283279
hab_uniq.append(hab)
284280

285281
return tod_uniq, hab_uniq
286-
282+
'''
287283
def make_daily_from_tod(tod):
288284
import re
289285
new_hab = {'type':'daily'}
@@ -386,12 +382,11 @@ def make_tod_from_hab(hab):
386382
tod['priority'] == 3
387383
else:
388384
tod['priority'] == 4
389-
390-
391-
392-
def matchDates(matchDict):
393-
'''Error/debugging script to match all hab dates with tod dates.'''
394-
from main import sync_hab2todo
385+
'''
386+
#def matchDates(matchDict):
387+
#'''Error/debugging script to match all hab dates with tod dates.'''
388+
#from main import sync_hab2todo
389+
'''
395390
for tid in matchDict:
396391
tod = matchDict[tid]['tod']
397392
hab = matchDict[tid]['hab']
@@ -412,6 +407,7 @@ def matchDates(matchDict):
412407
r = update_hab(newHab)
413408
matchDict[tid]['hab'] = newHab
414409
rList.append(r,hab.name)
410+
'''
415411

416412
def openMatchDict():
417413
import pickle
@@ -514,6 +510,7 @@ def sync_hab2todo_todo(hab, tod):
514510
new_hab = HabTask(habDict)
515511
return new_hab
516512

513+
'''
517514
def syncHistories(matchDict):
518515
519516
"""
@@ -578,37 +575,7 @@ def syncHistories(matchDict):
578575
print(hab.due)
579576
tod_user.commit()
580577
return matchDict
581-
582-
def tod_login(configfile):
583-
logging.debug('Loading todoist auth data from %s' % configfile)
584-
585-
try:
586-
cf = open(configfile)
587-
except IOError:
588-
logging.error("Unable to find '%s'." % configfile)
589-
exit(1)
590-
591-
config = configparser.SafeConfigParser()
592-
config.readfp(cf)
593-
594-
cf.close()
595-
596-
# Get data from config
597-
try:
598-
rv = config.get('Todoist', 'api-token')
599-
600-
except configparser.NoSectionError:
601-
logging.error("No 'Todoist' section in '%s'" % configfile)
602-
exit(1)
603-
604-
except configparser.NoOptionError as e:
605-
logging.error("Missing option in auth file '%s': %s" % (configfile, e.message))
606-
exit(1)
607-
608-
tod_user = todoist.TodoistAPI(rv)
609-
#tod_user = todoist.login_with_api_token(rv)
610-
# Return auth data
611-
return tod_user
578+
'''
612579

613580
def update_hab(hab):
614581
import requests
@@ -642,9 +609,11 @@ def update_hab_matchDict(hab_tasks, matchDict):
642609
if 'alias' in hab.task_dict.keys():
643610
try:
644611
tid = int(hab.alias)
612+
tid = hab.alias
645613
tid_list.append(tid)
646614
except:
647615
aliasError.append(hab)
616+
tid = None
648617
if tid in matchDict.keys():
649618
try:
650619
date1 = hab.due.date()

0 commit comments

Comments
 (0)