gpt4 book ai didi

Python 过滤器脚本

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:42 25 4
gpt4 key购买 nike

在我的ftp服务器中包含一个记录所有下载记录的日志文件,我想使用Python获取该文件并输出一个简化的文件,其中包含最近一周或7天的记录。/CliMb/xxx 中的日志文件如 ..。

Sat Jun  2 03:32:13 2012 [pid 12461] CONNECT: Client "66.249.68.236"
Sat Jun 2 03:32:13 2012 [pid 12460] [ftp] OK LOGIN: Client "66.249.68.236", anon password "gxxglxxxxt@google.com"
Sat Jun 2 03:32:14 2012 [pid 12462] [ftp] OK DOWNLOAD: Client "66.249.68.236", "/pub/10.5524/100001_101000/100022/readme.txt", 451 bytes, 1.39Kbyte/sec
Sat Jun 2 03:32:22 2012 [pid 12677] CONNECT: Client "66.249.68.236"
Sat Jun 2 03:32:23 2012 [pid 12676] [ftp] OK LOGIN: Client "66.249.68.236", anon password "xxxxxbot@google.com"
Sat Jun 2 03:35:27 2012 [pid 12706] [ftp] FAIL DOWNLOAD: Client "66.2

谢谢。

最佳答案

import time
lines = []
with open("somelog.txt") as f:
lines = [line for line in f]
def OnlyRecent(line):
return time.strptime(line.split("[")[0].strip(),"%a %b %d %h:%m:%s %Y") < (time.time()-(60*60*24*5)) #5 days old
print "\n".join(filter(OnlyRecent,lines))

至少是这样的......

关于Python 过滤器脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12273649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com