def list_available_lists(): gt = Gtasks() available_list = gt.get_lists() list_names = [] list_index = 0 i = 1 if len(available_list) > 1: print("These are your avaliable task list, please choose one: ") for task_list in available_list: print("{0}) {1}".format(i,task_list)) list_names.append(task_list) i=i+1 list_index = input("Choose a list by the number: ") while int(list_index) < 0 or int(list_index) > len(list_names): print(list_index) print("Choose a playlist available on the list.") list_index = input("Choose a playlist by the number: ") print ("Gonna syncronize notion tasks with this task list {0}".format(list_names[int(list_index)-1])) else: print("There is only one list available, so don't need to choose.") list_names.append(available_list[0]) list_index = 0 final_id = list_names[int(list_index)-1] return str(final_id)
def backup(target_list, include): if include == "all": include_hidden = True elif include == "visible": include_hidden = False else: include_hidden = True g = Gtasks() lists = g.get_lists() if target_list: original_count = len(lists) lists = [l for l in lists if l.title.lower() == target_list.lower()] new_count = len(lists) if not lists: print( f"Could not find any lists with the name '{target_list}' to backup!" ) return else: print(f"Backing up {new_count} of {original_count} lists.") print(f"Including hidden tasks" if include_hidden else "Not including hidden tasks") content = [] for l in lists: print(f"Adding list to backup: {l.title}") content.append(_serialize_list(l, include_hidden=include_hidden)) _backup_to_file(content)
def update_tasks(self): gt = Gtasks() task_list = -1 try: task_list = gt.get_tasks() except HTTPError as err: if err.code == 503: print("Google Tasks service unavailable. Refresh skipped.") else: print(f"HTTP error in update_tasks() : {err.code}") raise if task_list != -1: # then task_list has been populated + is safe to iterate over tasks_dict = {} # Get all the root tasks first for task in task_list: if task.parent == None: # then this is a root task - add to dict tasks_dict[task.title] = [] # Get all the subtasks for task in task_list: if task.parent != None: # then this is a subtask - add to its parent prnt = task.parent tasks_dict[prnt.title].append(task.title) tasks_str = "" for task in tasks_dict: tasks_str += ("> " + task + "\n") for subtask in tasks_dict[task]: tasks_str += (" - " + subtask + "\n") tasks_str += ("Last updated: " + datetime.now().strftime("%a, %d %b at %H:%M")) # Set word wrap length to suit Button width self.tasksButton.configure(wraplength=400) # Add string to button self.tasksButton.configure(text=tasks_str) self.after(self.auto_refresh_time_ms, self.update_tasks)
def _find_list_with_name(name): """Returns single list that matched if we found a match, or None if it's not sure. Will print debug info if not found. """ g = Gtasks() lists = g.get_lists() available_list_names = [l.title for l in lists] matching_lists = [l for l in lists if l.title.lower() == name.lower()] if len(matching_lists) > 1: print( f"Found {len(matching_lists)} lists that match name, not sure which to use: {name}" ) return None if len(matching_lists) == 0: print(f"Could not find any lists that match that name: {name}") print("Available list names:") print(", ".join(available_list_names)) return None return matching_lists[0]
def lists(): g = Gtasks() lists_ = g.get_lists() names = [l.title for l in lists_] print("Found Lists:") print("\n".join(names))
def authenticate(): """Simply construct a Gtasks object which will prompt authentication.""" Gtasks()
def gettoday(): #get today's date return date.today() def build_tasks_list(task_list): global tasks #needs to be global so tasks can be used outside of def tasks = gt.get_list(task_list) def Add_task(TaskDesc, TaskDate): #add new task to selected list tasks.new_task(TaskDesc, TaskDate) if __name__ == "__main__": gt = Gtasks() task_list = input("Enter name of list to update: " ) #Needs to be existing task list at this time. build_tasks_list(task_list) print("1- Add Individual Sunday Tasks") print("2- Add multiple tasks (today's date)") print("3- Add Standard Sunday Task List") menu = input("Selection: ") if menu == '1': task_Desc = input("Task Description: ") Add_task(task_Desc, getnextsunday()) elif menu == '2': lines = [] while True: line = input("Task Description (if done just press enter):") if line: