Ejemplo n.º 1
0
async def on_message(message):

    # Do not reply to self

    if message.author == client.user:
        return

    if message.content.startswith('!help'):
        await message.channel.send(
            'Log time in minutes spent on continuous learning. use !log \
        followed by a number... ex `!log 50 minutes watching a kubecon firetalk.`'
        )
        return
    if message.content.startswith('!log'):
        try:
            parsed_message = re.match(
                r'\!log\ (?P<value>\d+) (minutes|^$)(?P<message>.*)',
                message.content)
            update_log(
                message.author.display_name,
                parsed_message.group('value'),
                parsed_message.group('message'),
            )
        except Exception as e:
            message.channel.send(f"error while logging {e}")
    return
Ejemplo n.º 2
0
    def read(self):
        """
        Main method of the class, first of all it will run the check of the type of the log file
        and then it will run the right request parser.
        """
        print("Reading from: " + self.name)
        update_log(text="READING FROM FILE " + self.name + "\n")
        log_type = self.check_log_type()

        if log_type:
            self.read_file_in_xfrl_mode()
        else:
            self.read_file_in_std_mode()
Ejemplo n.º 3
0
 def parse_new_line_xfrl(self, line, old_request):
     """
     This method will analise the new line of the log file (which is in xferlog standard mode), if a download
     is found it will, create an object Request_xfrl and add the new request to the database if is a new one.
     """
     line = line.split(" ")
     if line[len(line) - 1] == "c\n" or line[len(line) - 1] == "c":
         request = Request_xfrl(line)
         if request.req_json["file_path"] != old_request.req_json["file_path"] or request.req_json["date"] > (
                 old_request.req_json["date"] + timedelta(seconds=10)):
             print("PARSED REQUEST RECEIVED AT: " + self.name + "\n" + str(request))
             update_log(text="PARSED REQUEST RECEIVED AT: " + self.name + "\n" + str(request))
             self.db.update_database(self.name, request)
             old_request = request
     return old_request
Ejemplo n.º 4
0
    def parse_new_line_std(self, line, old_request):
        """
        This method will analise the new line of the log file (which is in standard mode), if a download is found it
        will, create an object Request_std and add the new request to the database if is a new one.
        """
        if "OK DOWNLOAD" in line:
            line = line.split("\"")
            request = Request_std(line)
            if request.req_json["file_path"] != old_request.req_json[
                    "file_path"] or request.req_json["date"] > (
                        old_request.req_json["date"] + timedelta(seconds=10)):
                print("PARSED REQUEST RECEIVED AT: " + self.name + "\n" +
                      str(request))
                update_log(text="PARSED REQUEST RECEIVED AT: " + self.name +
                           "\n" + str(request))
                self.db.add_request_database(self.name, request)
                old_request = request
        if "OK UPLOAD" in line:
            line = line.split("\"")
            new_file = Request_std(line)
            self.postgres_db.add_new_file(new_file, ID)

        return old_request