python:当文件中出现特定字符串时执行robot用例
2023-09-11 14:21:03 时间
#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()
相关文章
- Python yaml模块使用
- Python虚拟环境的安装和配置-virtualenv与windows下多个python版本共存
- Python 获取文件版本信息
- 第三百六十节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的基本概念
- Python 日期和时间_python 当前日期时间_python日期格式化
- Python中利用原始套接字进行网络编程的示例
- 在Python中操作文件之truncate()方法的使用教程
- python文件和目录操作方法大全(含实例)【python】
- python:pip升级pip本身和setuptools(Python 3.7.15)
- 刚入行Python年薪就26万了,为什么Python岗位薪资越来越高?
- Python:python语言中与时间有关的库函数简介、安装、使用方法(获取当前时间/计算程序块前后运行时间/模型训练时间或耗费时间)之详细攻略
- Python语言学习:基于python五种方法实现使用某函数名【func_01】的字符串格式('func_01')来调用该函数【func_01】执行功能
- Python语言学习之字母S开头函数使用集锦:set/sys/super用法之详细攻略
- python实现复制文件功能
- 30天进阶Python,这个 Github 项目你值得拥有!
- python操作adb代码
- 【华为机试 Python实现】HJ61 放苹果(简单)
- python之制作MP3文件
- Python编程:列表、集合、字典推导式的示例
- Python爬虫:使用newspaper解析新闻页面信息
- 【Android 逆向】使用 Python 代码解析 ELF 文件 ( PyCharm 中创建 Python 程序 | 导入 ELFFile 库 | 解析 ELF 文件 )
- Python setup.py install 包含指定静态文件(打包时包含静态文件)
- 小学生蓝桥杯Python闯关 | 统计组合
- Python笔记:使用pywin32处理excel文件
- python+pytest接口自动化 —— 参数关联
- python 统计文件top IP
- python基础===一行 Python 代码实现并行(转)
- Python open()文件的字符数与指针字节关系
- 【异常】前端ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 〖Python自动化办公篇⑰〗- PPT 文件自动化 - PPT 插入表格与图片
- 【Python实战】 ---- python 实现 CSDN 的定时自动签到
- 【Python】.tsp文件的读取
- 【Python】3.python实现图片上传到阿里云OSS