예제 #1
0
def cancel(current_day):
    os.system("clear")
    ui.print_other_date(current_day)
    ui.print_current_day_events(current_day, count="yes")
    meeting_no = ui.gather_input(input_type=int, title="Which event you want to cancel? Type the number: ")
    plans = storage.read_from_file(current_day)
    if plans:
        del plans[meeting_no-1]
        storage.update_file(plans, current_day)
    if current_day == NOW:
        main()
    else:
        other_day_menu(current_day)
예제 #2
0
def print_current_day_events(current_day, count="no"):
    schedule = storage.read_from_file(current_day)
    if schedule:
        print("Your schedule for the day: ")
        schedule = [x.strip() for x in schedule]
        if count == "yes":
            for i in range(len(schedule)):
                print(f"{i+1}.   {schedule[i]}")
            print()
        else:
            for element in schedule:
                print(element)
            print()
    else:
        print("No plans for the day.")
        print()
예제 #3
0
def check_event_conflicts(start_hour, end_hour, current_day):
    data = storage.read_from_file(current_day)
    if data:
        data = [x.split("⸻") for x in data]
        data = [x[0] for x in data]
        data = [x.split("-") for x in data]
        data = [[hour.strip() for hour in hours] for hours in data]
        start_hour = datetime.datetime.strptime(start_hour, "%H:%M").time()
        end_hour = datetime.datetime.strptime(end_hour, "%H:%M").time()

        for event in data:
            start_event = datetime.datetime.strptime(event[0], "%H:%M").time()
            end_event = datetime.datetime.strptime(event[1], "%H:%M").time()
            if start_event < start_hour < end_event or start_event < end_hour < end_event:
                user_resolve = input("Time conflict found. Do you want to schedule event anyways? [Y/N] ")
                if user_resolve.lower() != "y":
                    return False
    return True
예제 #4
0
파일: calendar.py 프로젝트: ezsana/Calendar
def choose():
    inputs = ui.get_inputs(['Please choose between the options: '])
    user_choice = inputs[0]
    if user_choice == 's':
        ui.simple_print('Schedule a new meeting.')
        storage.schedule()
    elif user_choice == 'c':
        storage.cancel()
    elif user_choice == 'm':
        ui.simple_print('Your schedule for the day:\n')
        storage.meetings_arranged_by_time()
    elif user_choice == 'e':
        ui.simple_print('Your schedule for the day: ')
        ui.simple_print(storage.read_from_file())
        storage.edit_meeting()
    elif user_choice == 't':
        ui.simple_print(storage.total_meeting_duration())
    elif user_choice == 'q':
        ui.simple_print('Your choice: q')
        sys.exit()
    else:
        raise KeyError('There is no such option.')
예제 #5
0
def sort_events(current_day):
    data = storage.read_from_file(current_day)
    data = [x.split("⸻") for x in data]
    for event in data:
        event[0] = event[0].split("-")

    for event in data:
        event[0][0] = datetime.datetime.strptime(event[0][0].strip(), "%H:%M").time()
        event[0][1] = datetime.datetime.strptime(event[0][1].strip(), "%H:%M").time()
        event[1] = event[1].strip(" ")

    data = sorted(data, key=lambda x: x[0][1])
    data = sorted(data, key=lambda x: x[0][0])

    for event in data:
        event[0][0] = (event[0][0].strftime("%H:%M")).zfill(2)
        event[0][1] = event[0][1].strftime("%H:%M").zfill(2)
        print(event[0][0])

        event[0] = " - ".join(event[0])
    data = [" ⸻    ".join(e) for e in data]

    storage.update_file(data, current_day)
예제 #6
0
def main():
    while True:
        appointments_data = storage.read_from_file()
        handle_day_schedule(appointments_data)
        upi.display_menu()
        choice = upi.user_choice()
        if choice == "s":
            appointments_data.append(handlers.schedule_meeting(appointments_data))
            storage.save_to_file(appointments_data)
        elif choice == "c":
            if appointments_data == []:
                print("ERROR: No meeting to cancel!\n")
            else:
                updated_appointments = handlers.cancel_meeting(appointments_data)
                storage.remove_data_from_file(updated_appointments)
        elif choice == "e":
            handlers.edit_meeting(appointments_data)
        elif choice == "d":
            upi.display_total_meeting_duration(appointments_data)
        elif choice == "m":
            handlers.compact_meetings(appointments_data)
        else:
            break
예제 #7
0
from ui import print_message, show_schedule
from checks import check_hour_combined, check_duration, check_end_hour_combined, check_cancel_hour, search_for_me
from storage import write_to_file, read_from_file

START_HOUR = 0
END_HOUR = 1
TITLE = 2
filename = 'meetings.txt'
schedule = read_from_file(filename)  
def kill():
    print_message('Exiting...')
    quit()

def scheduler(schedule,pop_index = None):
    if pop_index != None:
        schedule.pop(pop_index)
    title = get_input('Meeting Title: ')
    start_hour = handle_hour()
    start_hour = int(start_hour)
    duration = handle_duration()
    end_hour = start_hour + duration
    while check_end_hour_combined(end_hour, END_HOUR, schedule) == None:
        duration = handle_duration()
        end_hour = start_hour + duration
    print_message('\nNew Meeting Created: {startHour} - {endHour} {Title}\n'.format(startHour = start_hour, 
                                                                                        endHour = end_hour, 
                                                                                        Title = title))    
    
    schedule.append([start_hour, end_hour, title])
    schedule = sort_schedule(schedule)
    write_to_file(schedule, filename)