Python Automation Cookbook
Explore the world of automation using Python recipes that will enhance your skills
Jaime Buelta
- 398 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Python Automation Cookbook
Explore the world of automation using Python recipes that will enhance your skills
Jaime Buelta
About This Book
Step-by-step instructions which take you through each program to automate monotonous tasks with Python 3.7
Key Features
- Automate integral business processes such as report generation, email marketing, and lead generation
- Build your first web application that scrapes data and accesses websites' APIs
- Create graphic-rich charts, graphs, and maps using Matplotlib
Book Description
Have you been doing the same old monotonous office work over and over again? Or have you been trying to find an easy way to make your life better by automating some of your repetitive tasks? Through a tried and tested approach, understand how to automate all the boring stuff using Python.
The Python Automation Cookbook helps you develop a clear understanding of how to automate your business processes using Python, including detecting opportunities by scraping the web, analyzing information to generate automatic spreadsheets reports with graphs, and communicating with automatically generated emails.
You'll learn how to get notifications via text messages and run tasks while your mind is focused on other important activities, followed by understanding how to scan documents such as résumés. Once you've gotten familiar with the fundamentals, you'll be introduced to the world of graphs, along with studying how to produce organized charts using Matplotlib. In addition to this, you'll gain in-depth knowledge of how to generate rich graphics showing relevant information.
By the end of this book, you'll have refined your skills by attaining a sound understanding of how to identify and correct problems to produce superior and reliable systems.
What you will learn
- Get to grips with scraping a website to detect changes
- Search and process raw sales files to aggregate information in spreadsheets
- Explore techniques to extract information from an Excel spreadsheet and generate exciting reports with graphs
- Discover the techniques required to generate random, print-friendly codes to be used as single-use coupons
- Automatically generate a marketing campaign, contacting the recipients over different channels
- Identify and implement precise solutions
Who this book is for
The Python Automation Cookbook is for you if you are a developer or anyone who wants to automate monotonous manual tasks related to fields such as finance, sales, and HR, among others.
Frequently asked questions
Information
Generating Fantastic Reports
- Creating a simple report in plain text
- Using templates for reports
- Formatting text in Markdown
- Writing a basic Word document
- Styling a Word document
- Generating structure in Word documents
- Adding pictures to Word documents
- Writing a simple PDF document
- Structuring a PDF
- Aggregating PDF reports
- Watermarking and encrypting a PDF
Introduction
Creating a simple report in plain text
Getting ready
How to do it...
- Import datetime:
>>> from datetime import datetime
- Create the template with the report in text format:
>>> TEMPLATE = '''
Movies report
-------------
Date: {date}
Movies seen in the last 30 days: {num_movies}
Total minutes: {total_minutes}
'''
- Create a dictionary with the values to store. Note this is the data that's going to be presented in the report:
>>> data = {
'date': datetime.utcnow(),
'num_movies': 3,
'total_minutes': 376,
}
- Compose the report, adding the data to the template:
>>> report = TEMPLATE.format(**data)
- Create a new file with the current date and store the report:
>>> FILENAME_TMPL = "{date}_report.txt"
>>> filename = FILENAME_TMPL.format(date=data['date'].strftime('%Y-%m-%d'))
>>> filename
2018-06-26_report.txt
>>> with open(filename, 'w') as file:
... file.write(report)
- Check the newly created report:
$ cat 2018-06-26_report.txt
Movies report
-------------
Date: 2018-06-26 23:40:08.737671
Movies seen in the last 30 days: 3
Total minutes: 376
How it works...
There's more...
See also
- The Using templates for reports recipe
- The Formatting text in Markdown recipe
- The Aggregating PDF reports recipe
Using templates for reports
Getting ready
$ echo "jinja2==2.20" >> requirements.txt
$ pip install -r requirements.txt
How to do it...
- Import Jinja2 Template and datetime:
>>> from jinja2 import Template
>>> from datetime import datetime
- Read the template from the files into memory:
>>> with open('jinja_template.html') as file:
... templat...