def read_content(
     self
 ):  # define procedure for file reading, skipping lines with incorrect format and returning list of correct lines
     f = open(self.file_path,
              "r")  # open file (by default 'content_source.txt')
     list_events = []  # define empty result
     for i in f:  # loop through the file lines
         event_properties = (i.rstrip()).split(
             "|")  # create list of the file line 'values'
         if len(
                 event_properties
         ) < 3:  # if this list has less then 3 values (not enough for content creation)
             print(
                 f"line '{i.rstrip()}' has been skipped cause of the wrong format"
             )
             self.successful_processing = "false"  # mark this object as having mistakes
         elif event_properties[
                 0] not in self.handling_types:  # if provided content type is not handled
             print(
                 f"line '{i.rstrip()}' has been skipped cause of the non-handling type of content"
             )
             self.successful_processing = "false"  # mark this object as having mistakes
         else:  # from current file line content can be created
             event_properties[1] = normilize_str(
                 event_properties[1])  # normalize 'text' value
             list_events.append(
                 event_properties
             )  # add list created from current file line to result
     return list_events  # return composed list[list[str]]
예제 #2
0
 def __set_values_from_console(
         self):  # define procedure for setting fields values from console
     user_input = InputClass()  # use object of InputClass
     self.text = user_input.read_str_input(
         "input user comment text:")  # input text
     self.text = normilize_str(self.text)  # normalize field "text"
     self.user_name = user_input.read_str_input(
         "input user name:")  # input city
예제 #3
0
 def __set_values_from_console(
         self):  # define procedure for setting fields values from console
     user_input = InputClass()  # use object of InputClass
     self.text = user_input.read_str_input(
         "input advertising text:")  # input text
     self.text = normilize_str(self.text)
     self.exp_date = user_input.read_date_input(
         "input advertising expiration date:"
     )  # input date (date input is corrected via console dialog)
예제 #4
0
 def __init__(self,
              values_source=None
              ):  # by default object will be created from console input
     Content.__init__(self)  # define fields from parent class
     if not values_source:  # create object from console(default)
         self.__set_values_from_console(
         )  # get object field's values from console (date input is corrected via console dialog)
     elif type(values_source) is dict:  # create file from dictionary
         try:  # if source dictionary has all required fields
             self.exp_date = datetime.datetime.strptime(
                 values_source["exp_date"], "%Y-%m-%d")
             self.text = normilize_str(
                 values_source["text"])  # set normalized text
         except KeyError:  # if some field name is missed
             self.mistakes_flag = 1  # set flag for mistakes from object creation
             print(
                 f"an Advert publication can not be created from dict {values_source}"
             )
         except ValueError:  # handle incorrect date
             print(
                 f"{values_source} date value is not using format 'YYYY-MM-DD' or provided date is not correct"
             )
             self.mistakes_flag = 1  # set flag for mistakes from object creation
         self.num_of_days = 0  # set num_of_days
         self.input_type = 'file_json'
     else:  # else - create object from file using list of values 'values_source'
         try:  # check whether date provided from file is correct and try to set 'exp_date' from this value
             self.exp_date = datetime.datetime.strptime(
                 values_source[2], "%Y-%m-%d")
         except ValueError:  # handle incorrect date
             print(
                 f"{values_source} date value is not using format 'YYYY-MM-DD' or provided date is not correct"
             )
             self.mistakes_flag = 1  # set flag for mistakes from object creation
         self.text = normilize_str(values_source[1])  # set text
         self.num_of_days = 0  # set num_of_days
         self.input_type = 'file_txt'  # set input_type
     self.type = 'Advertising'  # common field for all types of fields setting
예제 #5
0
 def __init__(self,
              values_source=None
              ):  # by default object will be created from console input
     Content.__init__(self)  # define fields from parent class
     if not values_source:  # create object from console(default)
         self.__set_values_from_console(
         )  # get object field's values from console
     elif type(values_source) is dict:  # create file from dictionary
         try:  # if source dictionary has all required fields
             self.city = values_source["city"]  # set city
             self.text = normilize_str(
                 values_source["text"])  # set normalized text
         except KeyError:  # if some field name is missed
             self.mistakes_flag = 1  # set flag for mistakes from object creation
             print(
                 f"a News publication can not be created from dict {values_source}"
             )
         self.input_type = 'file_json'
     else:  # else - create object from file using list of values 'values_source'
         self.city = values_source[2]  # set city
         self.text = normilize_str(values_source[1])  # set text
         self.input_type = 'file_txt'  # set input_type
     self.type = 'News'  # common field for all types of fields setting
예제 #6
0
 def __set_values_from_console(
         self):  # define procedure for setting fields values from console
     user_input = InputClass()  # use object of InputClass
     self.text = user_input.read_str_input("input news text:")  # input text
     self.text = normilize_str(self.text)
     self.city = user_input.read_str_input("input news city:")  # input city