• 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()
  • 相关阅读:
    simple-LDAP-auth
    User Attributes
    webpack 模块标识符(Module Identifiers)
    详解webpack中的hash、chunkhash、contenthash区别
    [转] 插件兼容CommonJS, AMD, CMD 和 原生 JS
    Exif.js 读取图像的元数据
    [转] 跨域
    [转] 理解Web路由
    [转] React 是什么
    [转] Web MVC简介
  • 原文地址:https://www.cnblogs.com/gcgc/p/11479538.html
Copyright © 2020-2023  润新知