Martynas-S / polybar-todoist

A polybar module to show the number of uncompleted todoist tasks
0 stars 0 forks source link

No longer working (exception error) #3

Open aadilayub opened 3 years ago

aadilayub commented 3 years ago

For the last 2 days, my tasks indicator looks like this: image

I took a look at the code to diagnose the issue:

def main():
    ICON = 'TASKS DUE TODAY:'
    EXCEPTION_REFRESH_RATE = 1

    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--prefix', default=ICON)
    parser.add_argument('-w', '--weekly', action='store_true')
    args = parser.parse_args()

    while True:
        try:
            api = load_api()

            print_loop(api, args.prefix, args.weekly)
        except Exception as error:
            # with open('errors.log', 'w') as file:
            #     file.write(str(error))

            print(f'{ICON} ~', flush=True)
            time.sleep(EXCEPTION_REFRESH_RATE)

It looks like the program is printing a tilde instead of the taskcount because of print(f'{ICON} ~', flush=True) which runs when the program is throwing an exception.

Any clue as to what could be causing this? AFAIK todoist hasn't announced any breaking API changes.

aadilayub commented 3 years ago

I uncommented the line that writes to errors.log, this is the result:

unconverted data remains: T17:0

According to this StackOverflow question, the problem is with how the strptime function is being used.

The relevant lines in todo.py are:

def item_due_today(dueDate):
    dueDate = dueDate[:15]
    dueTimestamp = datetime.strptime(dueDate, '%Y-%m-%d')
    today = datetime.today()

and

        if dueDate is not None:
            dueDate = dueDate[:15]
            dueTimestamp = datetime.strptime(dueDate, '%Y-%m-%d')
aadilayub commented 3 years ago

From the shell output:

Traceback (most recent call last):                                                                                               
  File "/home/aadil/.config/polybar/todoist/todo.py", line 96, in main                                                             
    print_loop(api, args.prefix, args.weekly)                                                                                      
  File "/home/aadil/.config/polybar/todoist/todo.py", line 55, in print_loop                                                       
    dueToday = due_today_count(api)                                                                                                
  File "/home/aadil/.config/polybar/todoist/todo.py", line 26, in due_today_count                                                  
    if dueDate is not None and item_due_today(dueDate) and not completed:                                                          
  File "/home/aadil/.config/polybar/todoist/todo.py", line 13, in item_due_today                                                   
    dueTimestamp = datetime.strptime(dueDate, '%Y-%m-%d')                                                                          
  File "/usr/lib64/python3.9/_strptime.py", line 568, in _strptime_datetime                                                        
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)                                                                 
  File "/usr/lib64/python3.9/_strptime.py", line 352, in _strptime                                                                 
    raise ValueError("unconverted data remains: %s" %                                                                              
ValueError: unconverted data remains: T17:0

of note:

  File "/usr/lib64/python3.9/_strptime.py", line 352, in _strptime                                                                 
    raise ValueError("unconverted data remains: %s" %    

does this mean %s needs to be added to our datetime format string? I tried changing it to %Y-%m-%d%s and %Y-%m-%d%S but that gave '%s' is a bad directive in format '%s' and "time data %r does not match format %r" respectively