Example #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
Example #2
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