Automate the Boring Stuff with Python

Home > Other > Automate the Boring Stuff with Python > Page 48
Automate the Boring Stuff with Python Page 48

by Al Sweigart


  A function call to ImageColor.getcolor('CornflowerBlue', 'RGBA') will return (100, 149, 237, 255), the RGBA value for that color.

  A box tuple is a tuple value of four integers: the left edge x-coordinate, the top edge y-coordinate, the width, and the height, respectively.

  Image.open('zophie.png')

  imageObj.size is a tuple of two integers, the width and the height.

  imageObj.crop((0, 50, 50, 50)). Notice that you are passing a box tuple to crop(), not four separate integer arguments.

  Call the imageObj.save('new_filename.png') method of the Image object.

  The ImageDraw module contains code to draw on images.

  ImageDraw objects have shape-drawing methods such as point(), line(), or rectangle(). They are returned by passing the Image object to the ImageDraw.Draw() function.

  Chapter 18

  Move the mouse to the top-left corner of the screen, that is, the (0, 0) coordinates.

  pyautogui.size() returns a tuple with two integers for the width and height of the screen.

  pyautogui.position() returns a tuple with two integers for the x- and y-coordinates of the mouse cursor.

  The moveTo() function moves the mouse to absolute coordinates on the screen, while the moveRel() function moves the mouse relative to the mouse’s current position.

  pyautogui.dragTo() and pyautogui.dragRel()

  pyautogui.typewrite('Hello world!')

  Either pass a list of keyboard key strings to pyautogui.typewrite() (such as 'left') or pass a single keyboard key string to pyautogui.press().

  pyautogui.screenshot('screenshot.png')

  pyautogui.PAUSE = 2

  Appendix D. Resources

  Visit http://nostarch.com/automatestuff/ for resources, errata, and more information.

  More no-nonsense books from NO STARCH PRESS

  PYTHON PLAYGROUND

  Geeky Weekend Projects for the Curious Programmer

  by MAHESH VENKITACHALAM

  OCTOBER 2015, 352 PP., $29.95

  ISBN 978-1-59327-604-1

  PYTHON CRASH COURSE

  A Hands-On, Project-Based Introduction to Programming

  by ERIC MATTHES

  NOVEMBER 2015, 560 PP., $39.95

  ISBN 978-1-59327-603-4

  THE LINUX COMMAND LINE

  A Complete Introduction

  by WILLIAM E. SHOTTS, JR.

  JANUARY 2012, 480 PP., $39.95

  ISBN 978-1-59327-389-7

  JAVASCRIPT FOR KIDS

  A Playful Introduction to Programming

  by NICK MORGAN

  DECEMBER 2014, 336 PP., $34.95

  ISBN 978-1-59327-408-5

  full color

  STATISTICS DONE WRONG

  The Woefully Complete Guide

  by ALEX REINHART

  MARCH 2015, 176 PP., $24.95

  ISBN 978-1-59327-620-1

  DATA VISUALIZATION WITH JAVASCRIPT

  by STEPHEN A. THOMAS

  MARCH 2015, 384 PP., $39.95

  ISBN 978-1-59327-605-8

  full color

  PHONE:

  800.420.7240 OR 415.863.9900

  EMAIL:

  [email protected]

  WEB:

  WWW.NOSTARCH.COM

  Index

  A note on the digital index

  A link in an index entry is displayed as the section title in which that entry appears. Because some sections have multiple index markers, it is not unusual for an entry to have several links to the same section. Clicking on any link will take you directly to the place in the text in which the marker appears.

  Symbols

  = (assignment) operator, String Concatenation and Replication, Comparison Operators

  $ (dollar sign), Character Classes, Matching Newlines with the Dot Character

  . (dot character), The Caret and Dollar Sign Characters, The Caret and Dollar Sign Characters, The Current Working Directory

  using in paths, The Current Working Directory

  wildcard matches, The Caret and Dollar Sign Characters

  " (double quotes), String Literals

  ** (exponent) operator, Entering Expressions into the Interactive Shell

  == (equal to) operator, Boolean Values, Comparison Operators

  / (forward slash), Entering Expressions into the Interactive Shell, The Multiple Assignment Trick, Files and File Paths

  division operator, Entering Expressions into the Interactive Shell, The Multiple Assignment Trick

  (backslash), Example Program: Magic 8 Ball with a List, String Literals, Creating Regex Objects, Matching Newlines with the Dot Character, Files and File Paths

  line continuation character, Example Program: Magic 8 Ball with a List

  > (greater than) operator, Boolean Values

  >= (greater than or equal to) operator, Boolean Values

  # (hash character), Multiline Strings with Triple Quotes

  // (integer division/floored quotient) operator, Entering Expressions into the Interactive Shell

  < (less than) operator, Boolean Values

  <= (less than or equal to) operator, Boolean Values

  % (modulus/remainder) operator, Entering Expressions into the Interactive Shell, The Multiple Assignment Trick

  * (multiplication) operator, Entering Expressions into the Interactive Shell, Getting a List’s Length with len(), The Multiple Assignment Trick

  != (not equal to) operator, Boolean Values

  () (parentheses), Mutable and Immutable Data Types, Review of Regular Expression Matching

  | (pipe character), Grouping with Parentheses, Managing Complex Regexes

  + (plus sign), Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and String Data Types, Getting a List’s Length with len(), The Multiple Assignment Trick, Optional Matching with the Question Mark, Matching Newlines with the Dot Character

  addition operator, Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and String Data Types, Getting a List’s Length with len(), The Multiple Assignment Trick

  ? (question mark), Matching Multiple Groups with the Pipe, Matching Newlines with the Dot Character

  ' (single quote), String Literals

  [] (square brackets), The List Data Type, Matching Newlines with the Dot Character

  * (star), Optional Matching with the Question Mark, The Wildcard Character, Matching Newlines with the Dot Character

  using with wildcard character, The Wildcard Character

  zero or more matches with, Optional Matching with the Question Mark

  - (subtraction) operator, Entering Expressions into the Interactive Shell, The Multiple Assignment Trick

  ^ (caret symbol), Character Classes, Character Classes, Matching Newlines with the Dot Character

  matching beginning of string, Character Classes

  negative character classes, Character Classes

  ''' (triple quotes), Escape Characters, Managing Complex Regexes

  _ (underscore), Variable Names

  : (colon), Blocks of Code, while Loop Statements, for Loops and the range() Function, Negative Indexes, Indexing and Slicing Strings

  {} (curly brackets), Dictionaries and Structuring Data, Matching One or More with the Plus, Matching One or More with the Plus, Matching Newlines with the Dot Character

  greedy vs. nongreedy matching, Matching One or More with the Plus

  matching specific repetitions with, Matching One or More with the Plus

  A

  %A directive, Pausing Until a Specific Date

  %a directive, Pausing Until a Specific Date

  absolute paths, The Current Working Directory

  abspath() function, The os.path Module

  addition (+) operator, Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and String Data Types, Getting a List’s Length with len(), The Multiple Assignment Trick

  additive color model, Colors and RGBA Values

  add_heading() method, Writing
Word Documents

  addPage() method, Creating PDFs

  add_paragraph() method, Writing Word Documents

  add_picture() method, Adding Headings

  add_run() method, Writing Word Documents

  algebraic chess notation, Pretty Printing

  all_caps attribute, Run Attributes

  ALL search key, Selecting a Folder

  alpha, defined, Computer Image Fundamentals

  and operator, Comparison Operators

  ANSWERED search key, Performing the Search

  API (application programming interface), Step 3: Write Out the CSV File Without the First Row

  append() method, Methods

  application-specific passwords, Logging in to the SMTP Server

  args keyword, Passing Arguments to the Thread’s Target Function

  arguments, function, Comments, def Statements with Parameters, Return Values and return Statements, Multithreading, Launching Other Programs from Python

  keyword arguments, Return Values and return Statements

  passing to processes, Launching Other Programs from Python

  passing to threads, Multithreading

  assertions, Assertions, Running Python Programs on OS X and Linux

  disabling, Running Python Programs on OS X and Linux

  assignment (=) operator, String Concatenation and Replication, Comparison Operators

  AT&T mail, Connecting to an SMTP Server, Retrieving and Deleting Emails with IMAP

  attributes, HTML, A Quick Refresher, Getting Data from an Element’s Attributes

  augmented assignment operators, The Multiple Assignment Trick

  B

  b backspace escape character, Step 3: Get and Print the Mouse Coordinates

  %B directive, Pausing Until a Specific Date

  %b directive, Pausing Until a Specific Date

  back() method, Sending Special Keys

  backslash (), String Literals, Creating Regex Objects, Matching Newlines with the Dot Character, Files and File Paths

  BarChart() function, Charts

  basename() function, Handling Absolute and Relative Paths

  BCC search key, Performing the Search

  Beautiful Soup, Parsing HTML with the BeautifulSoup Module

  (see also bs4 module)

  BeautifulSoup objects, Parsing HTML with the BeautifulSoup Module

  BEFORE search key, Selecting a Folder

  binary files, Finding File Sizes and Folder Contents, Writing to Files

  binary operators, Comparison Operators

  bitwise or operator, Managing Complex Regexes

  blank strings, The Integer, Floating-Point, and String Data Types

  blocking execution, The time.time() Function

  blocks of code, Mixing Boolean and Comparison Operators

  BODY search key, Selecting a Folder

  bold attribute, Run Attributes

  Boolean data type, Flow Control, Comparison Operators, Binary Boolean Operators, continue Statements, The in and not in Operators, The in and not in Operators

  binary operators, Comparison Operators

  flow control and, Flow Control

  in operator, The in and not in Operators

  not in operator, The in and not in Operators

  “truthy” and “falsey” values, continue Statements

  using binary and comparison operators together, Binary Boolean Operators

  box tuples, Coordinates and Box Tuples

  breakpoints, debugging using, Debugging a Number Adding Program

  break statements, An Annoying while Loop, for Loops and the range() Function

  overview, An Annoying while Loop

  using in for loop, for Loops and the range() Function

  browser, opening using webbrowser module, Web Scraping

  bs4 module, Parsing HTML with the BeautifulSoup Module, Parsing HTML with the BeautifulSoup Module, Creating a BeautifulSoup Object from HTML, Getting Data from an Element’s Attributes

  creating object from HTML, Parsing HTML with the BeautifulSoup Module

  finding element with select() method, Creating a BeautifulSoup Object from HTML

  getting attribute, Getting Data from an Element’s Attributes

  overview, Parsing HTML with the BeautifulSoup Module

  built-in functions, Importing Modules

  bulleted list, creating in Wiki markup, Project: Adding Bullets to Wiki Markup, Project: Adding Bullets to Wiki Markup, Project: Adding Bullets to Wiki Markup, Step 1: Copy and Paste from the Clipboard, Step 3: Join the Modified Lines

  copying and pasting clipboard, Project: Adding Bullets to Wiki Markup

  joining modified lines, Step 3: Join the Modified Lines

  overview, Project: Adding Bullets to Wiki Markup

  separating lines of text, Step 1: Copy and Paste from the Clipboard

  C

  calling functions, Comments

  call stack, defined, Raising Exceptions

  camelcase, Variable Names

  caret symbol (^), Character Classes, Character Classes, Matching Newlines with the Dot Character

  matching beginning of string, Character Classes

  negative character classes, Character Classes

  Cascading Style Sheets (CSS), Creating a BeautifulSoup Object from HTML, Finding Elements on the Page

  matching with selenium module, Finding Elements on the Page

  selectors, Creating a BeautifulSoup Object from HTML

  case sensitivity, Variable Names, Case-Insensitive Matching

  CC search key, Performing the Search

  Cell objects, Getting Sheets from the Workbook

  cells, in Excel spreadsheets, Working with Excel Spreadsheets, Getting Sheets from the Workbook, Creating and Removing Sheets, Setting Row Height and Column Width

  accessing Cell object by its name, Getting Sheets from the Workbook

  merging and unmerging, Setting Row Height and Column Width

  writing values to, Creating and Removing Sheets

  center() method, The join() and split() String Methods, Image Recognition

  chaining method calls, Rotating and Flipping Images

  character classes, The findall() Method, Matching Newlines with the Dot Character

  character styles, Styling Paragraph and Run Objects

  charts, Excel, Freeze Panes

  chdir() function, The Current Working Directory

  Chrome, developer tools in, Viewing the Source HTML of a Web Page

  clear() method, Finding Elements on the Page

  click() function, Clicking the Mouse, Review of the PyAutoGUI Functions, Project: Automatic Form Filler

  clicking mouse, Clicking the Mouse

  click() method, Finding Elements on the Page

  clipboard, using string from, Step 3: Handle the Clipboard Content and Launch the Browser

  CMYK color model, Colors and RGBA Values

  colon (:), Blocks of Code, while Loop Statements, for Loops and the range() Function, Negative Indexes, Indexing and Slicing Strings

  color values, Computer Image Fundamentals, Colors and RGBA Values

  CMYK vs. RGB color models, Colors and RGBA Values

  RGBA values, Computer Image Fundamentals

  column_index_from_string() function, Converting Between Column Letters and Numbers

  columns, in Excel spreadsheets, Converting Between Column Letters and Numbers, Formulas

  setting height and width of, Formulas

  slicing Worksheet objects to get Cell objects in, Converting Between Column Letters and Numbers

  Comcast mail, Connecting to an SMTP Server, Retrieving and Deleting Emails with IMAP

  comma-delimited items, The List Data Type

  command line arguments, Step 1: Figure Out the URL

  commentAfterDelay() function, Pressing and Releasing the Keyboard

  comments, Comments, Multiline Strings with Triple Quotes

  multiline, Multiline Strings with Triple Quotes

  ove
rview, Comments

  comparison operators, Boolean Values, Binary Boolean Operators

  overview, Boolean Values

  using binary operators with, Binary Boolean Operators

  compile() function, Creating Regex Objects, Review of Regular Expression Matching, Managing Complex Regexes

  compressed files, Walking a Directory Tree, Compressing Files with the zipfile Module, Extracting from ZIP Files, Extracting from ZIP Files, Step 3: Form the New Filename and Rename the Files

  backing up folder into, Step 3: Form the New Filename and Rename the Files

  creating ZIP files, Extracting from ZIP Files

  extracting ZIP files, Extracting from ZIP Files

  overview, Walking a Directory Tree

  reading ZIP files, Compressing Files with the zipfile Module

  computer screen, Pauses and Fail-Safes, Controlling Mouse Movement

  coordinates of, Pauses and Fail-Safes

  resolution of, Controlling Mouse Movement

  concatenation, The Integer, Floating-Point, and String Data Types, Getting a List’s Length with len()

  of lists, Getting a List’s Length with len()

  string, The Integer, Floating-Point, and String Data Types

 

‹ Prev