Beispiel #1
0
 def handle_data(self, data):
     # print('tag '+data) #DEBUG
     if self.is_header > 0:
         self.is_header += 1
         # print('Pippo '+str(self.is_header)) # DEBUG
     data = data.strip()
     # needed to manage multiple teacher lines
     is_append = False
     if self.immolation:
         # count the 4 lines of data for the lesson (subject, teacher, rooms, address)
         if self.dataLine <= 3:
             # pass #DEBUG
             if data == '/':
                 self.dataLine -= 1
                 is_append = True
             if self.dataLine == 0:
                 self.lesson.subject = data.upper()
                 print(self.lesson.subject)  #DEBUG
             if self.dataLine == 1:
                 self.lesson.teacher = self.lesson.teacher + data.upper()
                 if is_append == True:
                     self.dataLine -= 1
                     is_append = False
                 print(self.lesson.teacher)  #DEBUG
             if self.dataLine == 2:
                 self.lesson.rooms = data.upper()
                 print(self.lesson.rooms)  #DEBUG
             if self.dataLine == 3:
                 self.lesson.address = data.upper()
                 print(self.lesson.address)  #DEBUG
             # print(data.upper())  # DEBUG
             self.dataLine += 1
         # if is the last line
         if self.dataLine == 4:
             print("--")  # DEBUG
             self.lesson.semesterStartDate = self.semesterStartDate
             self.lesson.semesterEndDate = self.semesterEndDate
             self.dataLine = 0
             self.lesson.persist()
             #         reset the entity
             self.lesson = Lesson()
     if self.is_header == 9:  # find the correct line
         # print(data.upper()) #DEBUG
         # extract the data information and foreach date create the datetime object
         line = data.split(sep="-")
         self.semesterStartDate = datetime.datetime.strptime(
             line[0], ": %A %d %B %Y ")
         self.semesterEndDate = datetime.datetime.strptime(
             line[1], " %A %d %B %Y")
         # print(self.semesterStartDate) #DEBUG
         # print(self.semesterEndDate) #DEBUG
         self.is_header = 0
Beispiel #2
0
 def __init__(self):  # Override here
     HTMLParser.__init__(self)
     # todo: add documentation
     self.immolation = False
     # is the line counter for parsing the header data
     self.is_header = 0
     # is the time of the firts hour of lessons. Mandatory to calculate the start hour from offsets
     self.firstHour = datetime.datetime.strptime("08:30", "%H:%M")
     # the lesson database entity
     self.lesson = Lesson()
     self.dataLine = 0
     self.semesterStartDate = datetime.datetime
     self.semesterEndDate = datetime.datetime