What interesting or useful things can be done with Python automation? 【Lebo TestPro】

Hello everyone, I am a python automation lecturer. I have been doing automation for more than six years, and automation has helped me a lot in the past six years.

Say a few simple things first, and think about the things that make you happy.

The first one I wrote a timer with automation, it's super simple~

from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
import os
#打印现在时间
def tick():
    print('Tick! The time is: %s' % datetime.now())
if __name__ == '__main__':
    print('Begin.....')
    # 加一个调度器    ps.调度器可以看作是一个由许多不同任务共享的定时器中断服务程序
    scheduler = BlockingScheduler()
    # 每个3秒执行一次
    scheduler.add_job(tick, 'cron', second='*/3', hour='*')
    # 每天凌晨1点执行
    # scheduler.add_job(tick, 'cron', hour='1', minute='0', second='0')
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        scheduler.shutdown()

This timer written in python needs to write or copy more than 30 daily newspapers first. It can be executed for me every day to send the weekly and monthly daily reports I wrote. As long as my program is always open, it can be sent automatically. now,

Tsk tsk tsk set a time period to execute it, and use your own code, that is very cool, others may have similar tools, but brother is not used to other people's writing.

Of course, there is more than one timer function in my program, so what else can I do? I also used python to write the function of the table. For example, I can directly use python to automatically get the content in the table and operate it, and then put it for you. code.

 -*- coding: utf-8 -*-
import xlrd
class ExcelTool(object):
    @staticmethod
    def getoneRow(filePath, sheetPage, row):
        '''
        获取某一行数据
        :param filePath:
        :param sheetPage:
        :param row:
        :return:
        '''
        excelFile = xlrd.open_workbook(filePath)
        sheet = excelFile.sheet_by_index(sheetPage)
        return sheet.row_values(row)

    @staticmethod
    def getoneCol(filePath, sheetPage, row):
        '''
        获取某一列数据
        :param filePath:
        :param sheetPage:
        :param row:
        :return:
        '''
        excelFile = xlrd.open_workbook(filePath)
        sheet = excelFile.sheet_by_index(sheetPage)
        return sheet.col_values(row)

    @staticmethod
    def getallRow(filePath, sheetPage):
        '''
        获取该sheet页下所有行数据
        :param filePath:
        :param sheetPage:
        :return:
        '''
        excelFile = xlrd.open_workbook(filePath)
        sheet = excelFile.sheet_by_index(sheetPage)
        res = []
        for x in range(sheet.nrows):
            # print(sheet.row_values(x))
            res.append(sheet.row_values(x))
        return res

How do you use this code?

Come on, let's see how it works

a=ExcelTool.getoneRow(file,1,0)
b=ExcelTool.getoneCol(file,1,0)
c=ExcelTool.getallRow(file,1)

This is how the code works, just run it

You can complete the function of taking data from excel for operation, does it feel cool?

Do I only have these functions? Of course not, I also wrote a lot of functions with python automation, let's put
insert image description here
it directly. Here is the interface automation I wrote about the client,

See that emailTool.py, it's about the tool I write to send emails to company leaders every day

Automatic timing every day, and then send emails, the content is obtained from the database, completely get rid of daily tasks, do not need to be done manually every day, please, start with learning python automation.

There are other tools in it, including tools for configuration files, tools for automatically sending emails, tools for automatically querying databases, tools for random numbers, tools for reading excel, tools for using cache database redis, etc. There are too many Now, in addition to writing these tools, I will mainly complete the use of python automation for testing, which greatly improves my testing efficiency, so that regression testing at any time is no longer a dream. Whenever I want to test the previous content, I will run the program again. Save time and effort, this program of mine can also produce a test report by itself, and continue to show you the picture of the test report.
insert image description here
This is the final report of python doing automated testing, and doing testing is also a good way to learn python automation.

You can get a high salary, or you can write interesting content yourself. It is fully automated, and you can stay there when you finish writing.

If you need it, you can ask me for the code~~

Learn Python from scratch with me~~
Introduction to Python Basics 01: The Method of Dictionary

Introduction to Python Basics Issue 02: Methods of Lists

Introduction to Python Basics 03: What are the methods for string content?
If you need the source code of various tools, you can send a private message, or find a teaching assistant: lebo5201

Guess you like

Origin blog.csdn.net/leboxy/article/details/110543204