Пример #1
0
def parseLog(file):
    participant = Participant()

    print("%-25s %s" % ("Parsing log:", file))
    f = open(file, "r", encoding=my_utils.getFileEncoding(file))

    for line in f:
        line_split = line.split()
        try:
            if len(line_split) == 0:
                pass
            elif line_split[0] == "CALLSIGN:":
                participant.callsign = line_split[1].upper()
            elif line_split[0] == "NAME:":
                participant.name = " ".join(line_split[1:])
            elif line_split[0] == "CATEGORY:":
                participant.category = " ".join(line_split[1:])
            elif line_split[0] == "QSO:":
                participant.log.append(Qso(line_split))
        except:
            print("Error in line: " + line)
            pass  # empty line

    if len(participant.callsign):
        print("Success!")
    else:
        print("Error!")

    return participant
Пример #2
0
 def _extract_participants(self, participant_data, read_state,
                           user_phone_number, self_gaia_id):
     # Builds a dictionary of the participants in a conversation/thread
     participant_list = {}
     for participant in participant_data:
         # Create a new participant and store its properties
         current_participant = Participant()
         current_participant.name = getattr(participant, "fallback_name",
                                            None)
         participant_id = getattr(participant, "id", None)
         current_participant.chat_id = self._try_int_attribute(
             participant_id, "chat_id")
         current_participant.gaia_id = self._try_int_attribute(
             participant_id, "gaia_id")
         current_participant.type = getattr(participant, "participant_type",
                                            None)
         # Parse participant phone details
         phone_number = getattr(participant, "phone_number", None)
         if phone_number is not None:
             current_participant.e164_number = getattr(
                 phone_number, "e164", None)
             i18n_data = getattr(phone_number, "i18n_data", None)
             if i18n_data is not None:
                 current_participant.country_code = getattr(
                     i18n_data, "country_code", None)
                 current_participant.international_number = getattr(
                     i18n_data, "international_number", None)
                 current_participant.national_number = getattr(
                     i18n_data, "national_number", None)
                 current_participant.region_code = getattr(
                     i18n_data, "region_code", None)
         # Sometimes the phone number is missing...
         # This only seems to happen for the user, not others
         if (current_participant.gaia_id is not None
                 and current_participant.gaia_id == self_gaia_id
                 and (current_participant.e164_number is None
                      and current_participant.international_number is None
                      and current_participant.national_number is None)):
             current_participant.e164_number = user_phone_number
             current_participant.international_number = user_phone_number
         participant_list[current_participant.gaia_id] = current_participant
     # Parse read_state to get latest_read_timestamp for each participant
     if read_state is not None:
         for participant_read_state in read_state:
             participant_id = getattr(participant_read_state,
                                      "participant_id", None)
             gaia_id = self._try_int_attribute(participant_id, "gaia_id")
             latest_read_timestamp = self._try_int_attribute(
                 participant_read_state, "latest_read_timestamp")
             if gaia_id in participant_list.keys():
                 participant_list[
                     gaia_id].latest_read_timestamp = latest_read_timestamp
     return participant_list
Пример #3
0
def parseLogs(logs_dir):
    """
    Reads all the logs in the supplied directory and parses the data into dictionary that is returned

    :param logs_dir: Directory where the log files are located
    :return: Dictonary of particpants. {callsign, participant object}
    :rtype: dict
    """
    participants = {}

    for filename in glob.glob(os.path.join(logs_dir, "*.*")):

        participant = Participant()

        logger.info("parsing log: " + filename)
        logfile = open(filename,
                       "r",
                       encoding=my_utils.getFileEncoding(filename))

        try:
            for line in logfile:
                line_split = line.split()
                try:
                    if len(line_split) == 0:
                        pass
                    elif line_split[0] == "CALLSIGN:":
                        participant.callsign = line_split[1].upper()
                    elif line_split[0] == "NAME:":
                        participant.name = " ".join(line_split[1:])
                    elif line_split[0] == "CATEGORY:":
                        participant.category = " ".join(line_split[1:])
                    elif line_split[0] == "QSO:":
                        participant.log.append(Qso(line_split))
                except:
                    logger.warning("Error in line (will be ignored): " + line)
                    pass  # empty line
        except Exception as e:
            logger.warning("Error in file (will be ignored): " + filename)
            logger.warning("Error: " + str(e))
            pass

        if len(participant.callsign):
            participants[participant.callsign] = participant
            logger.info("Parsed log for: " + participant.callsign + "\n")
        else:
            logger.error("Couldn't parse the file: " + filename + "\n")

    return participants
 def addNewParticipantNamed(self, nameString) -> None:
     if not self.hasParticipantNamed(nameString):
         participant = Participant()
         participant.name = nameString
         self.participants.append(participant)
     self.sort()
 def addNewParticipantNamed(self, nameString):
     if not self.hasParticipantNamed(nameString):
         participant = Participant()
         participant.name = nameString
         self.participants.append(participant)
     self.sort()