我刚开始学python,代码有一些错误,无法运行。所以你能帮我解决这个问题吗?表明
File "ex2.py", line 21
if isRobotRecord(line)
^
SyntaxError: invalid syntax
ex2.py
import time
robot_emails = ["googlebot@google.com"]
robot_emails.append("66.249.74.228")
robot_emails.append("61.147.110.22")
robot_emails.append("61.147.110.21")
robot_emails.append("61.147.112.231")
f = open("/opt/CLiMB/Storage1/log/vsftp.log")
def isRobotRecord(line):
for email in robot_emails:
if email in line.split("Client")[1]:
return False
return True
def OnlyRecent(line):
if time.strptime(line.split("[")[0].strip(),"%a %b %d %H:%M:%S %Y")> time.gmtime(time.time()-(60*60*24*7)):
return True
return False
filename= time.strftime('%Y%m%d')+'.log'
f1= open(filename,'w')
for line in f:
if OnlyRecent(line):
if isRobotRecord(line)
print line
f1.write(line)
f.close()
f1.close()