python +appium实现企业微信自动打卡

APP:

利用appium启动企业微信,通过企业微信自动触发自动打卡。并截图。后续通过邮件发送附件至邮箱

from appium import webdriver
import time


class APP:
    def __init__(self, desired_caps, image_name):
        self.url = "http://127.0.0.1:4723/wd/hub"
        self.driver = webdriver.Remote(self.url, desired_caps)
        self.driver.implicitly_wait(10)
        self.desired_caps = desired_caps
        self.image_name = image_name

    def clock_in(self):

        time.sleep(10)
        self.driver.find_element_by_android_uiautomator('new UiSelector().text("工作台")').click()
        time.sleep(10)
        self.driver.find_element_by_android_uiautomator('new UiSelector().text("打卡")').click()
        time.sleep(10)
        self.driver.get_screenshot_as_file(self.image_name+".png")
        self.driver.lock(10)
        self.driver.quit()








 

支持多台手机打卡,

deviceList 打卡终端

receiverList  收件邮箱

2个list 顺序必须对应

 

from datetime import datetime
import random
import time
from appUItest.clock_in import APP
from appUItest import sendmail


note3 = {
    "platformName": "Android",
    "platformVersion": "8.1.0",
    "deviceName": "4b72a0f0",
    "udid": "4b72a0f0",
    "appPackage": "com.tencent.wework",
    "appActivity": "com.tencent.wework.launch.LaunchSplashActivity",
    "noReset": True
}

mix2 = {
    "platformName": "Android",
    "platformVersion": "8.0.0",
    "deviceName": "3261beaa",
    "udid": "3261beaa",
    "appPackage": "com.tencent.wework",
    "appActivity": "com.tencent.wework.launch.LaunchSplashActivity",
    "noReset": True
}


print("start!!!!!", datetime.now())

deviceList = ["mix2", "note3"]
receiverList = ["[email protected]", "[email protected]"]


try:
    while True:
        if datetime.now().isoweekday() not in (6, 7):  # 判断不为周末
            if datetime.now().time().hour in (9, 18, 19):  # 判断当前小时数
                if datetime.now().time().minute >= random.randint(20, 50) or datetime.now().time().minute >= 50:
                    print("启动。。。。。。。。。。。。")
                    for i in range(len(deviceList)):
                        print(deviceList[i])
                        desired_caps = (eval(deviceList[i]))
                        app = APP(desired_caps, deviceList[i])
                        app.clock_in()
                        sendmail.send_email(receiverList[i], "成功!,%s" % datetime.now(), deviceList[i])
                        print("完成")
                        time.sleep(120)
                    time.sleep(3600)
                time.sleep(60)
                continue
            time.sleep(120)
        print("不满足条件............未完成", datetime.now())
        time.sleep(600)
except Exception as e:
    print("失败", e)
    # sendmail.send_email(receiverList[0], "警告:打卡失败!!!!,%s" % datetime.now(), "deviceList")
    # clock_in.clock_in(note3, "note3",47230)

邮件

sender 发件邮箱

pwd 密码

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage


def send_email(receiver, msg_info, image_name):
    host = 'smtp.163.com'
    # 设置发件服务器地址
    port = 465
    # 设置发件服务器端口号。注意,这里有SSL和非SSL两种形式,现在一般是SSL方式
    sender = '[email protected]'
    # 设置发件邮箱,一定要自己注册的邮箱
    pwd = 'xxxxxxx'
    # 设置发件邮箱的授权码密码,根据163邮箱提示,登录第三方邮件客户端需要授权码
    receiver = receiver
    # 设置邮件接收人,可以是QQ邮箱
    # 设置邮件正文,这里是支持HTML的
    # msg = MIMEText(msg, 'html')
    msg = MIMEMultipart()
    msg.attach(MIMEText(msg_info, 'plain', 'utf-8'))
    # 设置正文为符合邮件格式的HTML内容
    msg['subject'] = '打卡通知'
    # 设置邮件标题
    msg['from'] = sender
    # 设置发送人
    msg['to'] = receiver
    # 设置接收人
    with open(image_name+".png", 'rb') as picAtt:
        msgImg = MIMEImage(picAtt.read())
        msgImg.add_header('Content-Disposition', 'attachment', filename=image_name+".png")
        # msgImg.add_header('Content-ID', '<0>')
        # msgImg.add_header('X-Attachment-Id', '0')
        msg.attach(msgImg)
    try:
        s = smtplib.SMTP_SSL(host, port)
        # 注意!如果是使用SSL端口,这里就要改为SMTP_SSL
        s.login(sender, pwd)
        # 登陆邮箱
        s.sendmail(sender, receiver, msg.as_string())
        # 发送邮件!
        print('Done.sent email success')
    except smtplib.SMTPException:
        print('Error.sent email fail')

 

 

 

你可能感兴趣的:(appium)