SHARE
TWEET

Untitled

a guest Oct 15th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3.  
  4. def create_schedule_file(input_filename: str, output_filename: str) -> None:
  5.     """Create schedule file from the given input file."""
  6.     dictionary_of_schedule_times = detect_schedule_time(get_list_from_file())
  7.     # 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]]
  8.     print(dictionary_of_schedule_times)
  9.  
  10.  
  11. def create_schedule_string(input_string: str) -> str:
  12.     """Create schedule string from the given input string."""
  13.     pass
  14.  
  15.  
  16. def get_list_from_file(filename: str) -> list:
  17.     """
  18.     Get the names of all registered competitors.
  19.  
  20.     :param filename: is the path to the file with the names of competitors.
  21.     :return: a list containing the names of competitors.
  22.     """
  23.     competitors_list = []
  24.     with open(filename, "r") as file:
  25.         for person in file:
  26.             competitors_list.append(person.strip())
  27.     return competitors_list
  28.  
  29.  
  30. def detect_schedule_time(input_data: list) -> dict:
  31.     """
  32.     Check if given list of strings contains schedule times.
  33.  
  34.     :param input_data: list
  35.     :return: list
  36.     """
  37.     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]+)"
  38.     valid_dictionary = {}
  39.     for line in input_data:
  40.         matches = re.finditer(regex, line, re.MULTILINE)
  41.         for match in matches:
  42.             hour = match.group(1) or match.group(2)
  43.             minute = match.group(3) or match.group(4)
  44.             subject = match.group(5)
  45.             valid_time = normalize(hour, minute)
  46.             # 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
  47.             # TODO append subject to a list located in valid_dictionary[valid_time]
  48.     return valid_dictionary
  49.  
  50.  
  51. def normalize(hour, minute):
  52.     valid_time = ""
  53.     if hour.startswith("0") and len(hour) > 1:
  54.         hour = hour[1:]
  55.     if len(minute) == 1:
  56.         minute = "0" + minute
  57.         print(hour, minute)
  58.  
  59.     # TODO construct valid time.
  60.  
  61.     return valid_time
  62.  
  63.  
  64. # def create_am_and_pm(hour, minute)
  65. #     kui tund on suurem kui 12, siis lahutada 12 ja lõppu panna PM. Muul juhul pane lõppu AM
  66.  
  67. if __name__ == '__main__':
  68.     print(create_schedule_string("wat 11:00 teine tekst 11:0 jah ei 10:00 pikktekst "))
  69.     create_schedule_file("schedule_input.txt", "schedule_output.txt")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top