Esempio n. 1
0
def run_task():
    import main
    from habitsUpdating import get_all_habits
    auth = main.get_started('auth.cfg')
    habits, response = get_all_habits(auth)
    for i in range(len(habits)):
        print('[%s] %s'% (i, habits[i].name))

    raw_updating = raw_input("Which habit would you like to complete? Please give me the number.    ")
    try:
        updating = int(raw_updating)
    except:
        print("I'm sorry, I need you to print just the number, please. Try again!")

    raw_number = raw_input("How many times would you like me to update it?    ")
    try:
        number = int(raw_number)
    except:
        print("I'm sorry, I need you to print just the number, please. Try again!")
    habit = habits[updating]
    rList = []
    for i in range(number):
        r = main.complete_hab(habit)
        rList.append(r)
    return rList
Esempio n. 2
0
def run_task():
    import main
    from habitsUpdating import get_all_habits
    auth = main.get_started('auth.cfg')
    habits, response = get_all_habits(auth)
    for i in range(len(habits)):
        print('[%s] %s' % (i, habits[i].name))

    raw_updating = raw_input(
        "Which habit would you like to complete? Please give me the number.    "
    )
    try:
        updating = int(raw_updating)
    except:
        print(
            "I'm sorry, I need you to print just the number, please. Try again!"
        )

    raw_number = raw_input(
        "How many times would you like me to update it?    ")
    try:
        number = int(raw_number)
    except:
        print(
            "I'm sorry, I need you to print just the number, please. Try again!"
        )
    habit = habits[updating]
    rList = []
    for i in range(number):
        r = main.complete_hab(habit)
        rList.append(r)
    return rList
Esempio n. 3
0
            matchDict[tid]['duelast'] = 'No'
    else:
        matchDict[tid]['duelast'] = 'NA'

#Check that anything which has recently been completed gets updated in hab
for tid in matchDict:
    tod = matchDict[tid]['tod']
    hab = matchDict[tid]['hab']
    if tod.recurring == 'Yes':
        if hab.dueToday == True:
            if hab.completed == False:
                if tod.dueToday == 'Yes':
                    matched_hab = main.sync_hab2todo(hab, tod)
                    r = main.update_hab(matched_hab)
                elif tod.dueToday == 'No':
                    r = main.complete_hab(hab)
                    print('Completed daily hab %s' % hab.name)
                    print(r)
                else:
                    print("error in daily Hab")
            elif hab.completed == True:
                if tod.dueToday == 'Yes':
                    fix_tod = tod_user.items.get_by_id(tid)
                    #                    fix_tod.close()
                    print('fix the tod! TID %s, NAMED %s' % (tid, tod.name))
                elif tod.dueToday == 'No':
                    continue
                else:
                    print("error, check todoist daily")
        elif hab.dueToday == False:
            try:
Esempio n. 4
0
def syncHistories(matchDict):

    """
    I wanted to see if I could convince recurring habs and tods to sync based on history. 
    Assuming both recur...
    """
    from dates import parse_date_utc
    from dateutil import parser
    from datetime import datetime
    from datetime import timedelta
    from main import complete_hab, update_hab
    from main import tod_login
    tod_user = tod_login('auth.cfg')
    todList = {}
    for tid in matchDict:
        try: 
            matchDict[tid]['recurs']
        except:
            print(tid)
            matchDict[tid]['recurs'] = matchDict[tid]['tod'].recurring
        if matchDict[tid]['recurs'] == 'Yes':
            hab = matchDict[tid]['hab']
            tod = matchDict[tid]['tod']
            habHistory = hab.history
            todHistory = tod.history
            try:
                lastTod = parser.parse(todHistory[0]['event_date']).date()
            except:
                lastTod = tod.due.date()
            habLen = len(habHistory) - 1
            try:
                lastHab = datetime.fromtimestamp(habHistory[habLen]['date']/1000).date() - timedelta(days=1)
            except:
                lastHab = hab.due.date() - timedelta(days=1)
            lastNow = datetime.today().date()
            if lastHab > hab.due.date(): 
                newHab = sync_hab2todo(hab, tod)
                r = update_hab(newHab)
            if lastTod != lastHab:
                if lastHab < lastTod and hab.dueToday == True:
                    print("Updating daily hab %s to match tod" % tod.name)
                    r = complete_hab(hab)
                    print(r)
                elif lastTod < lastHab: # and hab.dueToday == False:
                    if lastTod < lastNow == False:
                        print("Updating daily tod %s to match hab" % tod.name)
                        #fix_tod = tod_user.items.get_by_id(tid)
                        #fix_tod.close() #this to be uncommented in a week or so
                        print(lastTod)
                        print(lastHab)
                        print(lastNow)
                    elif hab.due.date() < lastNow:
                        print("Hey, tod %s looks like it's getting pretty late. Think about tackling that one?" % tod.name)
                        print(lastTod)
                        print(lastHab)
                        print(hab.due)
                else:
                    print("This one doesn't apply, right?")
                    print(tod.name)
                    print(lastTod)
                    print(lastHab)
                    print(hab.due)
    tod_user.commit()
    return matchDict
Esempio n. 5
0
def syncHistories(matchDict):
    """
    I wanted to see if I could convince recurring habs and tods to sync based on history. 
    Assuming both recur...
    """
    from dates import parse_date_utc
    from dateutil import parser
    from datetime import datetime
    from datetime import timedelta
    from main import complete_hab, update_hab
    from main import tod_login
    tod_user = tod_login('auth.cfg')
    todList = {}
    for tid in matchDict:
        try:
            matchDict[tid]['recurs']
        except:
            print(tid)
            matchDict[tid]['recurs'] = matchDict[tid]['tod'].recurring
        if matchDict[tid]['recurs'] == 'Yes':
            hab = matchDict[tid]['hab']
            tod = matchDict[tid]['tod']
            habHistory = hab.history
            todHistory = tod.history
            try:
                lastTod = parser.parse(todHistory[0]['event_date']).date()
            except:
                lastTod = tod.due.date()
            habLen = len(habHistory) - 1
            try:
                lastHab = datetime.fromtimestamp(
                    habHistory[habLen]['date'] /
                    1000).date() - timedelta(days=1)
            except:
                lastHab = hab.due.date() - timedelta(days=1)
            lastNow = datetime.today().date()
            if lastHab > hab.due.date():
                newHab = sync_hab2todo(hab, tod)
                r = update_hab(newHab)
            if lastTod != lastHab:
                if lastHab < lastTod and hab.dueToday == True:
                    print("Updating daily hab %s to match tod" % tod.name)
                    r = complete_hab(hab)
                    print(r)
                elif lastTod < lastHab:  # and hab.dueToday == False:
                    if lastTod < lastNow == False:
                        print("Updating daily tod %s to match hab" % tod.name)
                        #fix_tod = tod_user.items.get_by_id(tid)
                        #fix_tod.close() #this to be uncommented in a week or so
                        print(lastTod)
                        print(lastHab)
                        print(lastNow)
                    elif hab.due.date() < lastNow:
                        print(
                            "Hey, tod %s looks like it's getting pretty late. Think about tackling that one?"
                            % tod.name)
                        print(lastTod)
                        print(lastHab)
                        print(hab.due)
                else:
                    print("This one doesn't apply, right?")
                    print(tod.name)
                    print(lastTod)
                    print(lastHab)
                    print(hab.due)
    tod_user.commit()
    return matchDict
Esempio n. 6
0
            try:
                hab.completed
            except:
                print(tid)
            if hab.completed == False:
                matched_hab = main.sync_hab2todo(hab, tod)
                r = main.update_hab(matched_hab)
            elif hab.completed == True:
                fix_tod = tod_user.items.get_by_id(tid)
                fix_tod.close()
                print('completed tod %s' % tod.name)
            else: 
                print("ERROR: check HAB %s" % tid)
        elif tod.complete == 1:
            if hab.completed == False:
                r = main.complete_hab(hab)
                print(r)
                if r.ok == True:
                    print('Completed hab %s' % hab.name)
                else:
                    print('check hab ID %s' %tid)
                    print(r.reason)
            elif hab.completed == True:
                expired_tids.append(tid)
            else: 
                print("ERROR: check HAB %s" % tid)
        else:
            print("ERROR: check TOD %s" % tid)

for tid in expired_tids:
    matchDict.pop(tid)