python 自动抓取网页新闻以及图片并存储到数据库中

详细参考:https://www.yuhuashi.info/post/97.html

 

下面就是Python 监控Oracle alert log的脚本,经过测试可用!
#coding=UTF-8
#引用下面3个模块
import io
import datetime
import time
import traceback

DayList=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'] #日期
KeyWordList=['ORA-','Error','Starting ORACLE instance','Shutting down instance','Archived'] #定义错误类型
SkipOldEventMinutes=5  #定义时间间隔
AlertLogFile=r'/u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log' #日志绝对路径
SkipOldEventDateTimeDelta=datetime.timedelta(minutes=SkipOldEventMinutes)  #定义时间格式:0:05:00
EventDate=datetime.datetime(1, 1, 1, 0, 0) #日期显示格式0001-01-01 00:00:00

try:
   with io.open(AlertLogFile,mode='r') as f:
        while True:
                line=f.readline()
                if len(line)>3 and line[0:3] in DayList:
                        EventDate=datetime.datetime.strptime(line.rstrip('\n'), '%a %b %d %H:%M:%S %Y')
                        if EventDate                                 continue
                elif len(line) > 3:
                        if EventDate < datetime.datetime.now()-SkipOldEventDateTimeDelta:
                            for w in KeyWordList:
                                if w in line:
                                     print('[%s] %s' % (EventDate, line.rstrip('\n')))
                            continue
                elif len(line) == 0:
                        time.sleep(0.5)
                else:
                        continue
except:
     print(traceback.format_exc())

你可能感兴趣的:(Python学习笔记)