python:当文件中出现特定字符串时执行robot用例

 

 

#coding:utf-8
import os
import datetime
import time


def execute_rpt_db_full_effe_cainiao_city():
    flag = True
    while flag:
            # 判断该文件是否存在
            # os.path.isfile("/home/ytospid/opt/docker/jsc_spider/jsc_spider/log/call_proc.log")
            # 存在则获取昨天日期字符串
            yesterday = datetime.datetime.now()+ datetime.timedelta(-1)
            yesterday_str = datetime.datetime.strftime(yesterday,'%Y%m%d')
            # 判断该日志文件中是否包含该字符串,如果存在则表示今日数据已经爬完入库

            with open('/home/ytospid/opt/docker/jsc_spider/jsc_spider/log/call_proc.log') as f:
                for line in f.readlines():
                    if yesterday_str in line:
                        # 再执行30场景检查该表
                        os.system("robot -i rpt_db_full_effe_cainiao_city -l case30_log.html -r case30_report.html -o case30_output.xml /home/ytospid/opt/spider_monitor/菜鸟指数爬虫监控/01_测试用例/接口测试用例/菜鸟指数爬虫结果监控.txt")
                        # print line
                        print '已执行30场景'
                        flag = False
                        return 'OK'
            print u'休眠5秒'
            time.sleep(60)
            execute_rpt_db_full_effe_cainiao_city()


if __name__ == '__main__':
    execute_rpt_db_full_effe_cainiao_city()
    

例子: 每5秒检查一次test.txt文件,如果出现“hello”,则打开计算器,

import os,time


def execute():

    with open('test.txt') as f:
        for line in f.readlines():
            if 'hello' in line:
                os.system("calc.exe")
                return
    print '休息10秒再试试'
    time.sleep(5)
    execute()


if __name__ == '__main__':
    execute()

 

转载于:https://www.cnblogs.com/gcgc/p/11479538.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页