简体   繁体   English

通过ZNC日志自动化吗?

[英]Automating through ZNC logs?

I am currently an oper for multiple irc servers, and I am trying to have a reliable way to log our channels due to a high amount of abuse. 我目前是多个irc服务器的管理员,由于滥用大量,我正在尝试一种可靠的方式来记录我们的频道。 I have for the current time been using pierc, but I need all the functionality of ZNC. 目前,我一直在使用Pierc,但是我需要ZNC的所有功能。

My question is, using python what would be a simple way to loop through the ZNC log directory to parse the logs into a mysql database. 我的问题是,使用python是循环遍历ZNC日志目录以将日志解析为mysql数据库的简单方法。 The directory looks like the following: 该目录如下所示:

username_ircnetwork_channel_20160209.log username2_ircnetwork2_channel_20160209.log username_ircnetwork_channel_20160209.log username2_ircnetwork2_channel_20160209.log

I know I can itterate through each file with something to this effect: 我知道我可以通过每个文件来达到此目的:

fileOpen = open("~/.znc/moddata/log/")
fileOpen = fileOpen.read().splitlines()
for line in fileOpen:
    do something

However I am at a loss at a clean way to cycle through the log directory to check each file. 但是,我不知道如何以干净的方式循环通过日志目录来检查每个文件。 Is there a decent way in python to accomplish this? python中是否有一种体面的方式来做到这一点?

You could use Python's os module with listdir and loop through the files: 您可以将Python的os模块与listdir一起listdir并遍历文件:

import os

path = '/path/to/logs/'
listing = os.listdir(path)

for infile in listing:
    with open(path + infile, 'rb') as f:
        content = f.read()
        # parse however you need

https://docs.python.org/2/library/os.html ↳https : //docs.python.org/2/library/os.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过脚本自动执行提交和推送操作 - Automating commit and push through mercurial from script 通过浏览器内的VNC连接自动执行任务 - Automating Tasks through a VNC Connection within a Browser 通过串行通信自动执行登录操作 - Automating log-in action through serial communication 遍历列表和自动化算法的问题 - Problem with Iterating through a list and automating algorithm 如何通过硒自动化时使用beautifulsoup打印href属性? - How to print the href attributes using beautifulsoup while automating through selenium? 自动通过多个路径位置并导出文件名 - Automating through multiple path locations and exporting file names Automating email through python with smtplib, using sending from gmail sending to iusd (school district), does not go through - Automating email through python with smtplib, using sending from gmail sending to iusd (school district), does not go through 遍历日志以获取用户,路径 - Grepping through logs to get user, path OSError: [WinError 193] 在 Python 中通过 Selenium ChromeDriver 和 Chrome 自动化时,%1 不是有效的 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application while automating through Selenium ChromeDriver and Chrome in Python 搜索大量日志(最好在Python中) - Searching through lots of logs (preferably in Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM