def test_date_list(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-2.csv'))
     target_date_list = [
         "2016-01-03", "2016-02-07", "2016-11-12", "2017-01-01",
         "2017-01-02", "2017-01-03", "2017-01-07"
     ]
     self.assert_equal(target_date_list, task_list.date_list())
 def test_read_from_file(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-1.csv'))
     self.assert_equal(7, len(task_list.tasks))
     task = task_list.tasks[0]
     self.assert_equal('2017-01-02', str(task.date))
     self.assert_equal('Test Task One', task.name)
     self.assert_equal(30, task.minutes)
     self.assert_equal('This is a wonderful test task', task.notes)
    def test_save_list_to_file(self):
        """This is where the output is written.
        The checks for the valididity of the data are being done manually
        """
        task_list = TaskList()
        task1 = Task()
        output_file_path = self.testing_files[0]
        task1.set_name('Test Task One')
        task1.set_minutes(30)
        task1.set_notes('This is a great test task')
        task_list.add_task(task1)

        self.assert_equal(True, task_list.save_to_file(output_file_path))
        self.assert_equal(True, os.path.isfile(output_file_path))
示例#4
0
文件: main.py 项目: Robstepa/ToDoGit
def main():
    system('clear')
    todo_list = TaskList()
    print('Welcome to my ToDo program, user...\n')
    menu = '1. Add task\n2. Modify your task\n3. Delete your item\n4. Mark item as done\n' + \
           '5. Display all tasks\n6. Display specific task\n7. Exit'
    while True:
        print(menu)
        user_input = input("Choose: ")
        system('clear')
        if user_input == '1':
            add_task(todo_list)
        if user_input == '7':
            break
        if len(todo_list.tasks) < 1:
            print('There is nothing to show...\n')
            continue
        else:  # You can`t use this before you add some task to your todo_list
            if user_input == '2':
                modify_task(todo_list)
            if user_input == '3':
                delete_task(todo_list)
            if user_input == '4':
                mark_task(todo_list)
                system('clear')
            if user_input == '5':
                print(todo_list)
                print('\n')
            if user_input == '6':
                display_specific_task(todo_list)
示例#5
0
 def __init__(self, application):
     QtWidgets.QMainWindow.__init__(self)
     self.app = application
     self.timer = self.startTimer(1000, QtCore.Qt.PreciseTimer)
     self.clock = ClockTable('America/Los_Angeles')
     self.task_time = TaskTime('Task time')
     self.btn_start = ControlButton('Start')
     self.btn_del = ControlButton('Delete')
     self.task_check = AvailabilityCheck()
     self.db = Storage()
     self.task_list = TaskList('Timing',
                               self.db.get_model(self.clock.get_date()[:7]),
                               self)
     self.b_screening = BrowserScreening()
     self.login = Login(self.app)
     self.init_connections()
     self.init_ui()
示例#6
0
    def run(self):

        projects = {}

        for project in self.asana_hipchat:
            projects[project] = {}
            completed_tasks = TaskList(project)
            upcomming_tasks = TaskList(project)
            unassigned_tasks = TaskList(project)

            tasks = self.asana.get("/projects/"+project+"/tasks?opt_fields=assignee,completed_at,name")
            if tasks.get('error', False):
                print "There was an error in your request"
                break

            tasks = tasks.get('data', False)

            for task in tasks:
                if task['completed_at'] and self.date_includes(task['completed_at']):
                    completed_tasks.add(task['assignee']['id'], task)
                elif task['assignee'] and not task['completed_at']:
                    upcomming_tasks.add(task['assignee']['id'], task)
                elif not task['assignee'] and not task['completed_at']:
                    unassigned_tasks.add(None, task)

            projects[project]['completed_tasks'] = completed_tasks
            projects[project]['upcomming_tasks'] = upcomming_tasks
            projects[project]['unassigned_tasks'] = unassigned_tasks

        users = self.asana.get("/users")
        if users.get('data', False):
            for user in users['data']:
                for project in projects:
                    if projects[project]['completed_tasks'].tasks_for(user['id']):
                        self.render_tasks(project, user['name'],  'completed_tasks', projects[
                                          project]['completed_tasks'].tasks_for(user['id']))
                    if projects[project]['upcomming_tasks'].tasks_for(user['id']):
                        self.render_tasks(project, user['name'], 'upcomming_tasks', projects[
                                          project]['upcomming_tasks'].tasks_for(user['id']))

        for project in projects:
            if projects[project]['unassigned_tasks'].num_tasks('unassigned') > 0:
                self.render_tasks(project, None, 'unassigned_tasks', projects[
                    project]['unassigned_tasks'].tasks_for('unassigned'), color='red')
示例#7
0
def main():
    data_file = os.path.join(get_data_path(), 'tasks.JSON')
    last_data_file = data_file + ".last"

    task_list = TaskList(data_file)
    task_list_cpy = TaskList(data_file)
    is_changed = False # Assume the task list is not modified

    parser = argparse.ArgumentParser(description='Manages task list.')
    parser.add_argument('-v','--verbose', action='count', help='display more information') # TODO: connect parser

    subparsers = parser.add_subparsers(required=True, dest='subcommand')

    ### List
    parser_list = subparsers.add_parser('list', help='List all tasks.', aliases=['ls','l'])
    parser_list.add_argument('-m', '--merge', action='store_true', dest='list_merge', help='merges all tracks into one large list')
    parser_list.add_argument('--nocolor','-n', action='store_false', dest='list_is_color', default=True, help='turns off terminal coloring')
    parser_list.add_argument('-t','--track', action='append', dest='list_tracks', choices=task_list.get_tracks(), help='the track to list')
    parser_list.add_argument('-e', '--enumerate', action='store_true', dest='list_is_enum', help='lists the tasks by their index within a track')
    parser_list.add_argument('-a','--all',  action='store_true', help='show all tasks, including completed') # TODO connect parser
    parser_list.add_argument('-c','--complete', action='store_true', help='show only complete tasks') #TODO connect parser
    parser_list.add_argument('-r','--random', action='store_true', dest='list_is_rand', help='randomize task order (cannot be used with the -e flag)') #TODO connect parser

    ### Add
    parser_add = subparsers.add_parser('add', help='Add a new task to the task list', aliases=['a'])
    parser_add.add_argument('new_task', help='the new task to add')
    parser_add.add_argument('-t','--track', dest='add_track', choices=task_list.get_tracks(), help='the track this task belongs to')

    ### Delete
    parser_del = subparsers.add_parser('delete', help='Delete a task', aliases=['del','d'])
    parser_del.add_argument('del_task_txt', nargs='?', type=str, help='the text of the task to delete')
    parser_del.add_argument('-n','--num', dest='del_task_num', type=int, help='delete a task by its index within a track instead of by text')
    parser_del.add_argument('-t','--track', dest='del_track', choices=task_list.get_tracks(), help='the track this task belongs to')
    parser_del.add_argument('--ignore_collisions', action='store_true', help='ignore task collisions, deleting the first found entry') #TODO

    ### Complete
    parser_comp = subparsers.add_parser('complete', help='Mark a task complete', aliases=['com','comp','c'])
    parser_comp.add_argument('comp_task_txt', nargs='?', type=str, help='the text of the task to complete')
    parser_comp.add_argument('-n','--num', dest='comp_task_num', type=int, help='complete a task by its index within a track instead of by text')
    parser_comp.add_argument('-t','--track', dest='comp_track', choices=task_list.get_tracks(), help='the track this task belongs to')
    parser_comp.add_argument('-u','--uncomplete', dest='is_incomplete', help='mark a task as incomplete') # TODO connect parser
    parser_comp.add_argument('--ignore_collisions', action='store_true', help='ignore task collisions, deleting the first found entry') #TODO




    ### Tracks #TODO connect parser
    parser_tracks = subparsers.add_parser('tracks', help='Manipulate task tracks', aliases=['track','tr'])
    track_subparsers = parser_tracks.add_subparsers(required=True, dest='tracks_action')

    # List tracks
    parser_list_track = track_subparsers.add_parser('list', help='List tracks', aliases=['ls','l'])
    parser_list_track.add_argument('-n','--nocolor', action='store_false', default=True, dest='color_track_list', help='flag to display colors of tracks.')

    # Add track #TODO connect parser
    parser_add_track = track_subparsers.add_parser('add', help='Add new task tracks', aliases=['a'])
    parser_add_track.add_argument('new_track', help='the new track to add')
    parser_add_track.add_argument('-d','--desc', dest='track_desc', help='description of the new track')
    parser_add_track.add_argument('-c','--color', dest='track_color', choices=color.COLORS, help='color of the new track')

    # Delete track #TODO connect parser
    parser_del_track = track_subparsers.add_parser('delete', help="Delete a task track. Fails if tasks are still inside unless forced; consider first transfering with 'tracks transfer'", aliases=['del','d'])
    parser_del_track.add_argument('del_track', help='the track to delete')
    parser_del_track.add_argument('-f','--force', action='store_true', dest='track_force_del', help='forces deletion, even if the given track still has tasks')

    # Transfer track #TODO make, connect parser
    # Rename track #TODO make, connect parser

    # Modify track
    parser_track_mod = track_subparsers.add_parser('modify', help='Modify a task track', aliases=['mod','m'])
    parser_track_mod.add_argument('mod_track', help='the track to modify')
    parser_track_mod.add_argument('-n','--name', dest='track_new_name', choices=color.COLORS, help='new name of the track')
    parser_track_mod.add_argument('-c','--color', dest='track_new_color', choices=color.COLORS, help='new color of the track')
    parser_track_mod.add_argument('-d','--desc', dest='track_new_desc', help='new description of the track')


    ### UNDO
    parser_undo = subparsers.add_parser('undo', help='Undos the last successful action')

    args = parser.parse_args()
    dargs = vars(args)
    print(args)

    print("")

    if not data_dir_exists():
        generate_data_dir()

    # Connect 'list' parser
    if args.subcommand.find('l') == 0:
        # Print task list
        print_header("TASKS")
        task_tracks = agrs.list_tracks if args.list_tracks else task_list.get_tracks()

        for track in task_tracks:
            if not args.list_merge:
                print_track_header(task_list, track, is_color=args.list_is_color)

            if args.list_is_color:
                print(task_list.get_track_color(track), end="")

            if not args.list_merge:
                print("")

            for i,task in enumerate(task_list.get_tasks_in_track(track)):
                line_marker = "{}.".format(str(i)) if args.list_is_enum else "-"
                line = " {} {}".format(line_marker, task.txt)
                if task.complete:
                    line = color.FAINT + line + color.NOT_FAINT
                print(line)

            print(color.END, end='' if args.list_merge else '\n')

    # Connect 'add' parser
    elif 'new_task' in dargs:
        task_list.add_task(args.new_task, track=args.add_track)

        track = TaskList.UNSORTED_TRACK if not args.add_track else args.add_track

        print("Wrote new task: '{}' to track '{}{}{}'".format(args.new_task, task_list.get_track_color(track),track,color.END))
        is_changed = True

    # Connect 'del' parser
    elif args.subcommand.find('d') == 0:
        if args.del_task_txt and args.del_task_num:
            parser.error('delete: conflicting args: specify exactly one of -n DEL_TASK_NUM or DEL_TASK_TXT')

        elif args.del_task_num:
            if not args.del_track:
                parser.error('delete: if delete index -n specified, --track is required')

            try:
                success = task_list.del_task(t_idx=args.del_task_num, track=args.del_track)
            except ValueError as err:
                print("Failed to delete task: {}".format(err))
                exit(0)
            if(success):
                print("Deleted task: #{} in track '{}': '{}'".format(args.del_task_num, args.del_track, success))
                is_changed = True
            else:
                print("Task #{} doesn't exist in track '{}'".format(args.del_task_num, args.del_track))
        elif args.del_task_txt:
            success = task_list.del_task(task=args.del_task_txt)
            if(success):
                print("Deleted task: '{}'".format(success))
                is_changed = True
            else:
                print("Could not find task: '{}'".format(args.del_task_txt))
        else:
            parser.error('delete: missing args: specify exactly one of -n DEL_TASK_NUM or DEL_TASK_TXT')

    # Connect 'comp' parser
    elif args.subcommand.find('c') == 0:
        if args.comp_task_txt and args.comp_task_num:
            parser.error('delete: conflicting args: specify exactly one of -n DEL_TASK_NUM or DEL_TASK_TXT')

        elif args.comp_task_num:
            if not args.comp_track:
                parser.error('complete: if delete index -n specified, --track is required')

            try:
                success = task_list.complete_task(t_idx=args.comp_task_num, track=args.comp_track)
            except ValueError as err:
                exit("Failed to complete task: {}".format(err))
            if(success):
                print("Completed task: #{} in track '{}': '{}'".format(args.comp_task_num, args.comp_track, success))
                is_changed = True
            else:
                print("Task #{} doesn't exist in track '{}'".format(args.comp_task_num, args.comp_track))
        elif args.comp_task_txt:
            success = task_list.complete_task(task=args.comp_task_txt)
            if(success):
                print("Completed task: '{}'".format(success))
                is_changed = True
            else:
                print("Could not find task: '{}'".format(args.comp_task_txt))
        else:
            parser.error('complete: missing args: specify exactly one of -n DEL_TASK_NUM or DEL_TASK_TXT')

    # Connect 'tracks' parser
    elif args.subcommand.find('tr') == 0:

        # List tracks
        if args.tracks_action.find('l') == 0:
            # TODO: Verbosity
            # TODO: #complete count

            print_header("TRACKS")
            raw_tracks = task_list.get_tracks()

            if args.color_track_list:
                tracks = [task_list.get_track_color(track) + track + color.END for track in raw_tracks]
            else:
                tracks = raw_tracks

            row = "\t{}\t\t{}\t{}\n"
            print(row.format(color.UNDERLINE + "NAME", "#TASKS", "DESCRIPTION" + color.END))

            for i,track in enumerate(tracks):
                print( row.format(track, len(task_list.get_tasks_in_track(raw_tracks[i])), task_list.get_track_desc(raw_tracks[i])) )


        # Add track
        elif args.tracks_action.find('a') == 0:
            color_code = color.__dict__[args.track_color] if args.track_color else color.PLAIN

            try:
                task_list.add_track(args.new_track, desc=args.track_desc, color=color_code)
            except ValueError as err:
                exit("tracks add: {}".format(err))

            print("Added track: '{}{}{}'".format(color_code,args.new_track.upper(), color.END))
            is_changed = True

        # Del track
        elif args.tracks_action.find('d') == 0:
            task_cnt = len(task_list.get_tasks_in_track(args.del_track))
            color_code = task_list.get_track_color(args.del_track)

            if task_cnt == 0 or args.track_force_del:
                try:
                    task_list.del_track(args.del_track)
                except ValueError as err:
                    exit("tracks add: {}".format(err))

                if args.track_force_del and task_cnt > 0:
                    print("Deleted {} tasks".format(task_cnt))
                print("Deleted track: '{}{}{}'".format(color_code, args.del_track, color.END))
                is_changed = True

            else:
                exit("tracks delete: track '{}{}{}' still has {} task(s); transfer task(s) or rerun with 'tracks delete --force'".format(color_code,args.del_track,color.END, task_cnt))

        # Mod track
        elif args.tracks_action.find('m') == 0:
            if args.track_new_name or args.track_new_color or agrs.track_new_desc:
                color_code = color.__dict__[args.track_new_color] if args.track_new_color else None

                task_list.set_track_attr(args.mod_track, new_color=color_code, new_name=args.track_new_name, new_desc=args.track_new_desc)

                name = args.track_new_name if args.track_new_name else args.mod_track
                color_code = color_code if color_code else task_list.get_track_color(name)

                print("Modified track: '{}{}{}'".format(color_code, name, color.END))
                is_changed = True
            else:
                parser.err("tracks modify: must specify some attributes to modify")

    elif args.subcommand == 'undo':
        if os.path.exists(last_data_file) and os.path.isfile(last_data_file):
            task_list = TaskList(last_data_file)
            os.remove(last_data_file)

            print("Undo action complete")
            is_changed = True
        else:
            exit("undo: no actions to undo")

    print("")

    if is_changed:
        task_list.write_to_file(data_file)
        task_list_cpy.write_to_file(last_data_file)
示例#8
0
 def __init__(self):
     self.filename = "work_log.csv"
     self.tasklist = TaskList()
     self.tasklist.read_task_from_file(self.filename)
示例#9
0
class Worklog():
    def __init__(self):
        self.filename = "work_log.csv"
        self.tasklist = TaskList()
        self.tasklist.read_task_from_file(self.filename)

    def search_by_date(self):
        for i, d in enumerate(self.tasklist.dates()):
            enum_list = [(i+1,d) for i,d in enumerate(self.tasklist.dates())]
            print(i+1, ':', d)
        while True:
            datereq = input("Select Number To See Tasks For A Date or (m) to Return to Main Menu: ").strip()
            if datereq == 'm':
                log.start_message()
            else:
                try:
                    datereq = int(datereq)

                except ValueError:
                    print("Invalid Entry")
                    continue

                else:
                    found = False
                    for i, d in enum_list:
                        for task in self.tasklist.task_list:
                            if datereq == i and task.date == d:
                                    found = True
                                    print("Date :", task.date,
                                          " Task:", task.task,
                                          " Minutes:", task.minutes,
                                          " Notes: ", task.notes
                                          )
                    if not found:
                        print("Invalid Entry. Please try again")

    def search_by_time(self):
        for i, m in enumerate(self.tasklist.minutes()):
            min_list = [(i+1,m) for i,m in enumerate(self.tasklist.minutes())]
            print(i+1, ':', m)
        while True:
            minreq = input("Select Number To See Time For Tasks or (m) to Return to Main Menu ").strip()
            if minreq == 'm':
                log.start_message()
            else:
                try:
                    minreq = int(minreq)
                except ValueError:
                    print("Invalid Entry")
                    continue

                else:
                    found = False
                    minreq = int(minreq)
                    for i, m in min_list:
                        for task in self.tasklist.task_list:
                            if minreq == int(i) and int(task.minutes) == m:
                                    found = True
                                    print("Date :", task.date,
                                          " Task:", task.task,
                                          " Minutes:", task.minutes,
                                          " Notes: ", task.notes
                                          )
                    if not found:
                        print("Invalid Entry. Please try again")



    def exact_search(self):
        while True:
            found = False
            exreq = input("Enter Text or (m) to Return to Main Menu: ").strip()
            if exreq == 'm':
                log.start_message()
            else:
                for task in self.tasklist.task_list:
                    if re.search(r'%s' % exreq, task.task, re.IGNORECASE) \
                            or re.search(r'%s' % exreq, task.notes, re.IGNORECASE):
                        found = True
                        print("Date :", task.date,
                              " Task:", task.task,
                              " Minutes:", task.minutes,
                              " Notes: ", task.notes
                              )
                if not found:
                    print("Invalid Entry. Please try again")

    def pattern_search(self):
        while True:
            found = False
            preq = input("Enter Text or (m) to Return to Main Menu: ").strip()
            if preq == 'm':
                log.start_message()
            else:
                for task in self.tasklist.task_list:
                    if preq in task.notes or preq in task.task:
                        found = True
                        print("Date :", task.date,
                              " Task:", task.task,
                              " Minutes:", task.minutes,
                              " Notes: ", task.notes
                              )
                if not found:
                    print("Invalid Entry. Please try again")

    def add_task(self):
        task = Task()
        task.input_task()
        task.input_minutes()
        task.input_notes()
        task.date = datetime.date.today()
        self.tasklist.app_task(task)
        self.tasklist.save_task_to_file(self.filename,task)

    def lookup_task(self):
        if len(self.tasklist.task_list) == 0:
            print("Nothing to lookup. Your task log is empty.\n")
            input("Hit Enter/Return to go back and add a task.")
        else:
            while True:
                lookup = input("Lookup by Date(D), Time(T), Exact Search(E) or Pattern(P): ")
                lookup.lower()

                if lookup == 'd':
                    self.search_by_date()
                    break
                elif lookup == 't':
                    self.search_by_time()
                    break
                elif lookup == 'e':
                    self.exact_search()
                    break
                elif lookup == 'p':
                    self.pattern_search()
                    break
                else:
                    print("Sorry invalid option. Please try again")

    def start_message(self):
        while True:

            q = input("Add New Task(1) or Lookup Task(2) or Quit(3): ".strip())

            try:
                q = int(q)

            except ValueError:
                print("Sorry that's an invalid entry. Please try again.")
                continue

            else:
                if q == 1:
                    self.add_task()

                elif q == 2:
                    self.lookup_task()

                elif q == 3:
                    exit()
 def test_tasks_with_regex(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-2.csv'))
     self.assert_equal(3, len(task_list.tasks_with_regex('s\w\wG')))
 def test_tasks_for_duration(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-2.csv'))
     self.assert_equal(2, len(task_list.tasks_for_duration(30)))
 def test_tasks_for_date(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-1.csv'))
     self.assert_equal(1, len(task_list.tasks_for_date('2017-01-02')))
     self.assert_equal(3, len(task_list.tasks_for_date('2017-01-03')))
 def test_start_with_empty_list(self):
     task_list = TaskList()
     self.assert_equal(0, len(task_list.tasks))
    def __init__(self):

        self.task_list = TaskList()
        self.data_file = 'data.csv'
        self.task_list.read_from_file(self.data_file)
 def test_durations(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-2.csv'))
     target_durations = [5, 30, 90, 120]
     self.assert_equal(target_durations, task_list.durations())
 def test_add_a_task(self):
     task_list = TaskList()
     task = Task()
     self.assert_equal(True, task_list.add_task(task))
     self.assert_equal(1, len(task_list.tasks))
 def test_tasks_with_string(self):
     task_list = TaskList()
     self.assert_equal(True,
                       task_list.read_from_file('tests/fixture-2.csv'))
     self.assert_equal(3, len(task_list.tasks_with_string('slug')))
示例#18
0
from task_list import TaskList
from task import Task
from sys import exit
import time
from display import Display

my_task_list = TaskList()
displays = Display()

MAIN_MENU = (
    "1: Display Tasks",
    "2: Add Tasks",
    "3: Mark Tasks Completed",
    "4: Remove Tasks",
    "0: Exit Program",
)

#BEGIN DICTIONARY

ADD_MENU = (
    "1: Add a New Task",
    "0: Return to Main Menu",
)

REMOVE_MENU = (
    "1: Remove Task From List",
    "0: Return to Main Menu",
)

COMPLETE_MENU = (
    "1: Mark Task Complete",
                       'Average situation awareness: {:2.2f}%'.format(
                           sum(self.situation_awareness) / len(self.situation_awareness) * 100)


# env = simpy.rt.RealtimeEnvironment(initial_time=0, factor=1 / 60 * 0.010, strict=False)
env = simpy.Environment()

# [env.process(task.task_execution()) for task in task_list]
user_memory = UserMemory(env)
machine = Machine()
road_conditions = RoadConditionsState(env)

task_list = TaskList(env,
                     sheet,
                     machine,
                     road_conditions,
                     user_memory,
                     persona=PERSON,
                     max_mental=params.get('MAX_COGNITIVE_WORKLOAD'),
                     max_perc=params.get('MAX_PERCEPT_WORKLOAD'))
user = User(env, user_memory, machine, road_conditions, task_list, params)
road_conditions_generator = RoadConditionsGenerator(env, machine, user_memory,
                                                    road_conditions, task_list,
                                                    params, scenario)

hmi_interface = HmiInterface(env, machine, road_conditions, user_memory,
                             task_list)

visualization = Visualization(env, task_list, road_conditions, machine,
                              user_memory)
# machine.on_event(env.timeout(0, value='TOR60_switch'))
env.run(until=SIM_TIME * 60)
class Worklog:
    def __init__(self):

        self.task_list = TaskList()
        self.data_file = 'data.csv'
        self.task_list.read_from_file(self.data_file)

    def add_item(self):
        task = Task()
        print("What should the name of this task be?")
        task.input_name()
        print("How many minutes did you spend on it?")
        task.input_minutes()
        print("Add any other notes (or hit Enter/Return to skip notes).")
        task.input_notes()
        self.task_list.add_task(task)
        self.task_list.save_to_file(self.data_file)
        print("\033c", end="")
        print("Your task has been added!")

    def initial_prompt(self):
        print("\033c", end="")
        print("### Welcome to Worklogger ###")

        while True:
            print()
            print("Choose an option:\n")
            print("  1. Add a new item")
            print("  2. Lookup an item")
            print("  3. Quit\n")
            get_input = input(
                "Enter the number of your selection (1-3): ").strip().lower()
            if get_input == '1':
                print("\033c", end="")
                self.add_item()
            elif get_input == '2':
                self.lookup_menu()
            elif get_input == '3':
                print("Thanks for using Worklogger!")
                break
            else:
                print("\033c", end="")
                print("That wasn't a valid option. Must be: 1-3. Try again.")

    def lookup_menu(self):
        print("\033c", end="")

        if len(self.task_list.tasks) == 0:
            print("Nothing to lookup. Your task log is empty.\n")
            input("Hit Enter/Return to go back and add a task.")
        else:
            while True:

                print("Lookup task by:\n")
                print("  1. Date")
                print("  2. Time spent")
                print("  3. Exact text search")
                print("  4. Pattern text search")
                print()
                get_input = input("Enter the number of your selection (1-4): "
                                  ).strip().lower()

                if get_input == '1':
                    self.search_by_date()
                    break
                elif get_input == '2':
                    self.search_by_duration()
                    break
                elif get_input == '3':
                    self.search_by_text()
                    break
                elif get_input == '4':
                    self.search_by_regex()
                    break
                else:
                    print("\033c", end="")
                    print(
                        "That wasn't a valid option. Must be: 1-4. Try again")

    def search_by_date(self):
        print("\033c", end="")
        print("Choose from one of the following dates: ")
        print()
        for date_index, date_string in enumerate(self.task_list.date_list()):
            print("  {}. {}".format(date_index + 1, date_string))
        while True:
            print()
            get_input = input(
                "Enter the number for the date you wish to see (1-{}): ".
                format(len(self.task_list.date_list()))).strip().lower()
            try:
                input_as_zero_based_int = int(get_input) - 1
            except ValueError:
                print("That isn't a valid option. Try again.")
                continue
            else:
                if input_as_zero_based_int >= 0 and input_as_zero_based_int < len(
                        self.task_list.date_list()):
                    print("\033c", end="")
                    request_date = self.task_list.date_list(
                    )[input_as_zero_based_int]
                    print("Here are the tasks you did on {}:\n".format(
                        request_date))
                    for task in self.task_list.tasks_for_date(request_date):
                        task.display()

                    input("\nPress Enter/Return to return to the main menu")
                    print("\033c", end="")
                    break
                else:
                    print("That isn't a valid option. Try again.")
                    continue

    def search_by_duration(self):
        print("\033c", end="")
        print("Choose from one of the following durations: ")
        print()
        for duration_index, duration in enumerate(self.task_list.durations()):
            print("  {}. {}".format(duration_index + 1, duration))
        while True:
            print()
            get_input = input(
                "Enter the number for the duration you wish to see (1-{}): ".
                format(len(self.task_list.durations()))).strip().lower()
            try:
                input_as_zero_based_int = int(get_input) - 1
            except ValueError:
                print("That isn't a valid option. Try again.")
                continue
            else:
                if input_as_zero_based_int >= 0 and input_as_zero_based_int < len(
                        self.task_list.durations()):
                    print("\033c", end="")
                    request_minutes = int(
                        self.task_list.durations()[input_as_zero_based_int])
                    print("Here are the tasks that took {} minutes:\n".format(
                        request_minutes))
                    for task in self.task_list.tasks_for_duration(
                            request_minutes):
                        task.display()

                    input("\nPress Enter/Return to return to the main menu")
                    print("\033c", end="")
                    break
                else:
                    print("That isn't a valid option. Try again.")
                    continue

    def search_by_regex(self):
        print("\033c", end="")
        print("Enter the regular expression you want to search with:")
        get_input = input("> ")
        list_of_tasks = self.task_list.tasks_with_regex(get_input)
        if len(list_of_tasks) > 0:
            print("\033c", end="")
            print(
                "Here are the tasks who's name or notes match the '{}' pattern:\n"
                .format(get_input))
            for task in list_of_tasks:
                task.display()
        else:
            print(
                "\nThe pattern '{}' doesn't match any task names or notes.\n")

        input("\nPress Enter/Return to return to the main menu")
        print("\033c", end="")

    def search_by_text(self):
        print("\033c", end="")
        print(
            "Enter the exact text you want to search for (case insensitive):")
        get_input = input("> ")
        list_of_tasks = self.task_list.tasks_with_string(get_input)
        if len(list_of_tasks) > 0:
            print("\033c", end="")
            print(
                "Here are the tasks with '{}' in the name or notes:\n".format(
                    get_input))

            for task in list_of_tasks:
                task.display()
        else:
            print()
            print("The string '{}' is not in any of your task names or notes.".
                  format(get_input))
            print()

        input("\nPress Enter/Return to return to the main menu")
        print("\033c", end="")

    def run_test(self, file_name):
        import sys
        system_input = sys.stdin
        test_input = open('tests/{}'.format(file_name), 'r')
        sys.stdin = test_input
        self.initial_prompt()
        test_input.close()
        sys.stdin = system_input
 def test_read_from_file_that_does_not_exist(self):
     task_list = TaskList()
     self.assert_equal(
         True, task_list.read_from_file('file-that-does-not-exist.csv'))
     self.assert_equal(0, len(task_list.tasks))
示例#22
0
def run_cli(play=True):

    #initialize task_list
    task_list = TaskList(url="https://beccas-task-list-c15.herokuapp.com/")
    
    # print choices
    options = list_options()

    while play==True:

        # get input and validate
        choice = make_choice(options, task_list)

        task_list.print_selected()

        if choice=='1':
            print_stars()
            for task in task_list.list_tasks():
                print(task)
        elif choice=='2':
            print("Great! Let's create a new task.")
            title=input("What is the title of your task? ")
            description=input("What is the description of your task? ")
            response = task_list.create_task(title=title, description=description)

            print_stars()
            print("New task:", response["task"])

        elif choice=='3':
            select_by = input("Would you like to select by? Enter title or id: ")
            if select_by=="title":
                title = input("Which task title would you like to select? ")
                task_list.get_task(title=title)
            elif select_by=="id":
                id = input("Which task id would you like to select? ")
                if id.isnumeric():
                    id = int(id)
                    task_list.get_task(id=id)
            else:
                print("Could not select. Please enter id or title.")
            
            if task_list.selected_task:
                print_stars()
                print("Selected task: ", task_list.selected_task)

        elif choice=='4':
            print(f"Great! Let's update the task: {task_list.selected_task}")
            title=input("What is the new title of your task? ")
            description=input("What is the new description of your task? ")
            response = task_list.update_task(title=title, description=description)

            print_stars()
            print("Updated task:", response["task"])
        elif choice=='5':
            task_list.delete_task()

            print_stars()
            print("Task has been deleted.")

            print_stars()
            print(task_list.list_tasks())

        elif choice=='6':
            response = task_list.mark_complete()

            print_stars()
            print("Completed task: ", response["task"])

        elif choice=='7':
            response = task_list.mark_incomplete()

            print_stars()
            print("Incomplete task: ", response["task"])

        elif choice=='8':
            for task in task_list.list_tasks():
                task_list.get_task(id=task['id'])
                task_list.delete_task()

            print_stars()
            print("Deleted all tasks.")
        elif choice=='9':
            list_options()
        elif choice=='10':
            play=False
            print("\nThanks for using the Task List CLI!")

        print_stars()
示例#23
0
class TrackerWindow(QtWidgets.QMainWindow):
    begin_task = QtCore.pyqtSignal()
    cancel_task = QtCore.pyqtSignal()
    complete_task = QtCore.pyqtSignal()

    def __init__(self, application):
        QtWidgets.QMainWindow.__init__(self)
        self.app = application
        self.timer = self.startTimer(1000, QtCore.Qt.PreciseTimer)
        self.clock = ClockTable('America/Los_Angeles')
        self.task_time = TaskTime('Task time')
        self.btn_start = ControlButton('Start')
        self.btn_del = ControlButton('Delete')
        self.task_check = AvailabilityCheck()
        self.db = Storage()
        self.task_list = TaskList('Timing',
                                  self.db.get_model(self.clock.get_date()[:7]),
                                  self)
        self.b_screening = BrowserScreening()
        self.login = Login(self.app)
        self.init_connections()
        self.init_ui()

    def init_ui(self):
        self.setWindowTitle(f'Time Tracker {__version__}')
        self.resize(640, 400)
        self.setWindowFlags(QtCore.Qt.MSWindowsFixedSizeDialogHint)
        content = QtWidgets.QWidget()
        grid = QtWidgets.QGridLayout(content)
        for item in (self.clock, self.task_time, self.task_list,
                     self.btn_start, self.btn_del, self.task_check,
                     self.login):
            item.setParent(content)

        grid.addWidget(self.clock, 0, 0)
        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self.task_time)
        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(self.btn_start)
        hbox.addWidget(self.btn_del)
        vbox.addLayout(hbox)
        grid.addLayout(vbox, 0, 1)
        grid.addWidget(self.task_check,
                       1,
                       0,
                       1,
                       2,
                       alignment=QtCore.Qt.AlignCenter)
        grid.addWidget(self.task_list,
                       2,
                       0,
                       1,
                       2,
                       alignment=QtCore.Qt.AlignCenter)
        self.setCentralWidget(content)

    def init_connections(self):
        self.btn_start.clicked.connect(self.start_task)
        self.btn_del.clicked.connect(self.delete_task)
        self.task_time.endTask.connect(self.add_task)

        self.begin_task.connect(lambda: self.btn_start.setText('Complete'))
        self.begin_task.connect(lambda: self.btn_del.setText('Cancel'))
        self.begin_task.connect(
            lambda: self.task_time.start(self.clock.get_time()))
        self.begin_task.connect(self.b_screening.stop)
        self.begin_task.connect(self.task_check.stop)

        self.complete_task.connect(self.task_time.stop)
        self.complete_task.connect(lambda: self.btn_start.setText('Start'))
        self.complete_task.connect(lambda: self.btn_del.setText('Delete'))

        self.cancel_task.connect(self.task_time.stop)
        self.cancel_task.connect(lambda: self.btn_start.setText('Start'))
        self.cancel_task.connect(lambda: self.btn_del.setText('Delete'))

        self.task_check.start_check.connect(self.b_screening.start)
        self.task_check.stop_check.connect(self.b_screening.stop)
        self.task_check.login.connect(self.login.login)
        self.task_check.logout.connect(self.login.logout)

        self.b_screening.task_av.connect(self.task_check.reset)
        self.login.login_success.connect(self.task_check.stop)
        self.login.login_success.connect(self.b_screening.stop)
        self.login.logout_success.connect(self.task_check.start)
        self.login.logout_success.connect(self.b_screening.start)

    def timerEvent(self, tme):
        self.clock.timerEvent(tme)
        self.task_time.timerEvent(tme)
        self.b_screening.timerEvent(tme)

    @QtCore.pyqtSlot()
    def start_task(self):
        if self.task_time.is_active():
            self.add_task()
        else:
            self.begin_task.emit()

    @QtCore.pyqtSlot()
    def add_task(self):
        self.complete_task.emit()
        self.db.insert(self.task_time.start_time, self.clock.get_time(),
                       self.task_time.value)
        self.task_list.task_list.setModel(
            self.db.get_model(self.clock.get_date()[:7]))
        self.task_list.init_ui(on_start=False)

    @QtCore.pyqtSlot()
    def delete_task(self):
        if self.task_time.is_active():
            self.cancel_task.emit()
        else:
            for index in self.task_list.task_list.selectedIndexes():
                if index.isValid():
                    item_id = index.data(QtCore.Qt.UserRole)
                    try:
                        int(item_id)
                    except ValueError:
                        continue
                    self.db.delete(item_id)
                    self.task_list.task_list.setModel(
                        self.db.get_model(self.clock.get_date()[:7]))
                    self.task_list.init_ui(on_start=False)