Python过滤器脚本 - python

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
                            
                        
                    
                
                                7年前关闭。
            
                    
在我的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 "[email protected]"
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 "[email protected]"
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 uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

Python:无法识别Pip命令 - python

这是我拍摄的屏幕截图。当我尝试在命令提示符下使用pip时,出现以下错误消息:pip无法识别为内部或外部命令,可操作程序或批处理文件。我已经检查了这个线程:How do I install pip on Windows?我所能找到的就是我必须将"C:\PythonX\Scripts"添加到我的类路径中,其中X代表python版本。如您在我的…

Python:如何将有效的uuid从String转换为UUID? - python

我收到的数据是 { "name": "Unknown", "parent": "Uncategorized", "uuid": "06335e84-2872-4914-8c5d-3ed07d2a2f16" }, 我需要将uuid从Strin…

Python 3会流行吗? - python

我已经学习了一些Python 2和Python 3,似乎Python 2总体上比Python 3更好。这就是我的问题所在。是否有充分的理由真正切换到python 3? 参考方案 总体上,甚至在大多数细节上,Python3都比Python2更好。关于第三方库, Python 3落后于的唯一区域是。使Python变得如此出色的原因不仅在于它作为一种语言的内在特性…