[英]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.