Python自动化

#!/usr/bin/env python
os.system(“gnome-terminal -e ‘bash -c “ls; exec bash”’”)

-- coding: utf-8 --

import linecache
#import pyautogui
import os
import re
import shutil
import time
import smtplib
import time
import random
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
mail_from = ‘shixinfa@baidu.com’
receiver = [mail_from,‘shixinfa@baidu.com’]

receiver = [mail_from]

mail_subject = ‘linux monkey test result’
##第0步下载对应的模块类库
def installdemo():
#cmd=(‘curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py’)
#os.system(cmd)
#time.sleep(100)
#cmdnext=(‘python get-pip.py’)
#os.system(cmdnext)
#time.sleep(10)
cmdpygui=(‘pip install pyautogui’)
os.system(cmdpygui)
##第1步拉取最新的代码
def gitpullcode():
##切换到你的项目目录,并执行代码拉取脚本
os.system(‘cd /home/sxf’)
os.system(‘cd /home/sxf/zhuxin/baidu/iov/sz/mapauto-interface’)
pullcode()

def pullcodedev():
os.system(‘git stash’)
os.system(‘git checkout dev’)
os.system(‘git pull’)
os.system(‘sleep 35s’)
def pullcode():
os.system(‘git stash’)
os.system(‘git checkout sdk-dev’)
os.system(‘git pull’)
os.system(‘sleep 35s’)

##第2步执行monkey脚本
def clickmonkey():
screenWidth, screenHeight=pyautogui.size()
print(“width========”)
print(screenWidth)
print(“Height========”)
print(screenHeight)
currentMouseX, currentMouseY=pyautogui.position()
print(“cureent poisttioncurrentMouseX======”)
print(currentMouseX)
print(“cureent poisttioncurrentMouseY======”)
print(currentMouseY)
for i in range(1, 10000):
pyautogui.moveTo(random.randint(120, screenWidth - 10), random.randint(0, screenHeight), 0)
pyautogui.click();
if (i % 500):
pyautogui.moveTo(98, 66, 0)
pyautogui.click();
if (i % 100
0):
pyautogui.moveTo(524, 161, 0)
pyautogui.click();
pyautogui.moveTo(800, 199, 1)
pyautogui.rightClick()
time.sleep(1)
pyautogui.moveTo(800, 354, 1)
pyautogui.click();
time.sleep(4)
pyautogui.moveTo(148, 722, 1)
pyautogui.click();
#第3步定时执行脚本
def timer(n):
‘’’’’
每n秒执行一次
‘’’
while True:
print(time.strftime(’%Y-%m-%d %X’,time.localtime()))
# 此处为要执行的任务
str = (‘python /Users/shixinfa/Documents/mapautomation/src/util/sendmail.py’)
os.system(str)
time.sleep(n)

##第4步计算是否有新的crash文件产生
def dircount(DIR):
print len(os.listdir(DIR))
return len(os.listdir(DIR))
##第5步生成测试报告
def testResult():
msg = MIMEMultipart(‘mixed’)
msg[‘Subject’] = mail_subject
msg[‘From’] = mail_from
msg[‘To’] = “;”.join(receiver)
html_text = ‘’’

开始测试时间20200612
结束测试时间20200613
crash发生时间20200614
crash个数20
crash log log link
''' ##添加日志附件 message = MIMEText(html_text, 'html') ##你存放日志文件的目录 zipFile = '/Users/shixinfa/Documents/Logs/20200612/sdf.zip' zipApart = MIMEApplication(open(zipFile, 'rb').read()) zipApart.add_header('Content-Disposition', 'attachment', filename=zipFile) msg.attach(message) msg.attach(zipApart) smtp = smtplib.SMTP() smtp.connect('proxy-in.baidu.com', 25) smtp.sendmail(mail_from, receiver, msg.as_string()) smtp.quit() if __name__ == '__main__': #testResult() length=dircount('/Users/shixinfa/Documents/Logs/20200612') print length if length>0: print "new data" else: print "no data" #installdemo(); #clickmonkey()
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值