Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def create_schedule_file(input_filename: str, output_filename: str) -> None:
- """Create schedule file from the given input file."""
- dictionary_of_schedule_times = detect_schedule_time(get_list_from_file())
- # TODO sort dictionary keys to sorted list and make a table out of em, where first column are the entries of sorted list and second column are the subjects in the valid_dictionary[sorted_entries[i]]
- print(dictionary_of_schedule_times)
- def create_schedule_string(input_string: str) -> str:
- """Create schedule string from the given input string."""
- pass
- def get_list_from_file(filename: str) -> list:
- """
- Get the names of all registered competitors.
- :param filename: is the path to the file with the names of competitors.
- :return: a list containing the names of competitors.
- """
- competitors_list = []
- with open(filename, "r") as file:
- for person in file:
- competitors_list.append(person.strip())
- return competitors_list
- def detect_schedule_time(input_data: list) -> dict:
- """
- Check if given list of strings contains schedule times.
- :param input_data: list
- :return: list
- """
- regex = r"(([0-1][0-9]|[2][0-4])|(?<![0-9])[0-9])\D(([0-5][0-9]|[0-9](?![0-9]))) +([a-zA-Z]+)"
- valid_dictionary = {}
- for line in input_data:
- matches = re.finditer(regex, line, re.MULTILINE)
- for match in matches:
- hour = match.group(1) or match.group(2)
- minute = match.group(3) or match.group(4)
- subject = match.group(5)
- valid_time = normalize(hour, minute)
- # TODO check if valid_dictionary already has key valid_time. if not. Add a new entry to valid_dictionary[valid_time] = [], where [] is a new list for all the time located on the same time
- # TODO append subject to a list located in valid_dictionary[valid_time]
- return valid_dictionary
- def normalize(hour, minute):
- valid_time = ""
- if hour.startswith("0") and len(hour) > 1:
- hour = hour[1:]
- if len(minute) == 1:
- minute = "0" + minute
- print(hour, minute)
- # TODO construct valid time.
- return valid_time
- # def create_am_and_pm(hour, minute)
- # kui tund on suurem kui 12, siis lahutada 12 ja lõppu panna PM. Muul juhul pane lõppu AM
- if __name__ == '__main__':
- print(create_schedule_string("wat 11:00 teine tekst 11:0 jah ei 10:00 pikktekst "))
- create_schedule_file("schedule_input.txt", "schedule_output.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement