Automating reports with Python

Slides:



Advertisements
Similar presentations
Little Used, but Powerful Features with GP Cathy Fregelette, CPA, PMP Practice Manager BroadPoint Technologies September 20, 2012.
Advertisements

Aqua Data Studio. Find the application We are using Aqua Data Studio v11.
© Paradigm Publishing, Inc Excel 2013 Level 2 Unit 2Managing and Integrating Data and the Excel Environment Chapter 7Automating Repetitive Tasks.
1 Computing for Todays Lecture 22 Yumei Huo Fall 2006.
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
An Introduction to ASP.NET Web Pages 2 Module 1: Webmatrix Installation and Your First Web Site Tom Perkins.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
This presentation will guide you though the initial stages of installation, through to producing your first report Click your mouse to advance the presentation.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Part 1. Persistent Data Web applications remember your setting by means of a database linked to the site.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
TEAM Basic TotalElectrostatic ManagementAwareness&
| nectar.org.au NECTAR TRAINING Module 10 Beyond the Dashboard.
1 Working with MS SQL Server Textbook Chapter 14.
Chapter 17 Creating a Database.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
WinCvs. WinCVS WinCvs is a window based version control system. Use WinCvs when  You want to save every version of your file you have ever created. CVS.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Excel Macros 1 Macros or, How to Automate Part of Your Spreadsheet or Worksheet.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
1 Terminology. 2 Requirements for Network Printing Print server Sufficient RAM to process documents Sufficient disk space on the print server.
Lesson 29: Building a Database. Learning Objectives After studying this lesson, you will be able to:  Identify key database design techniques  Open.
Using SQL for Patron Card Expiration Reminders For Norcal IUG – Nov. 20, 2015 At the Berkeley Public Library.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Institute for the Protection and Security of the Citizen HAZAS – Hazard Assessment ECCAIRS Technical Course Provided by the Joint Research Centre - Ispra.
PHP Form Processing * referenced from
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
Downloading and Installing GRASP-AF Workshop Ian Robson Information Analyst, North of England Cardiovascular Network.
XP Creating Web Pages with Microsoft Office
SQL Database Management
Fundamental of Databases
A step-by-Step Guide For labels or merges
Data Virtualization Demoette… ODBC Clients
Development Environment
MET4750 Techniques for Earth System Modeling
Working with SQL Server for Linux Cross-Platform
SQL and SQL*Plus Interaction
Practical Office 2007 Chapter 10
How to Fi
PYTHON: AN INTRODUCTION
Create Virtual Directory Windows 8 - IIS 8.5
Database application MySQL Database and PhpMyAdmin
mysql and mysql workbench
How to add the packages for printing decision trees
Microsoft Access Illustrated
Microsoft Excel 2003 Illustrated Complete
Exam Braindumps
Types of SQL Commands Farrokh Alemi, PhD
How to Import an Excel File
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Aqua Data Studio.
Automating Reports with Python
Making PowerShell Useful
Creating and Modifying Queries
Making PowerShell Useful
MIS2502: Data Analytics MySQL and SQL Workbench
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Tutorial 6 PHP & MySQL Li Xu
Install MySQL Community Server and MySQL Workbench
Windows Installation Tutorial
Chapter 1: Programming Basics, Python History and Program Components
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Input and Output Python3 Beginner #3.
SETUP ALEXA APP Setup Alexa on your favorite device and control your smart device with the help of Alexa.
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Presentation transcript:

Automating reports with Python NorCal IUG 2017 November 17, 2017 www.gemstonelogan.com/presentations.html

Why Automate? Staff time Allows more time for other things Reports are delivered on a consistent schedule Will work while staff is on vacation, in meetings, sick, etc. Reduces repetitive work

How? Simple solution: Use a combination of bat files, SQL scripts, Blat, and Scheduled Tasks Pros: Relatively simple Cons: Limiting formatting More robust: Use a programming language, SQL script (or API), bat file, and Scheduled Tasks Pros: Very customizable and can create beautiful spreadsheets Cons: More initial setup

One Approach Install Python

Installing Python: Anaconda https://www.anaconda.com/download/

One Approach Write a one-line program and test Add a shebang line and doc string Refine your existing code (comment, reorganize, add variable, etc)

Editors: Any Plain Text Editor Notepad Any Windows computer will have this Simple – probably too simple Notepad++ Syntax highlighting, substantial improvement over Notepad Geany Easy to run Python straight from the editor gVim Not a good beginning editor

One-line Python program

Running a program Hello World C:\Users\gemst\Documents\IUG2018\WeeklyNew>python hello.py Hello World (This assumes you added Python to your path during installation.)

Add a shebang line and doc string #!/usr/bin/env python3 """Print Hello World to the command line.""" # Print "Hello World" print ("Hello World!")

One Approach (Continued) Try creating an empty spreadsheet with xlsxwriter Add some formatting Try writing some text to the spreadsheet Refine your existing code (comment, reorganize, add variable, etc)

Creating a Spreadsheet #!/usr/bin/env python3 """Create a spreadsheet.""" import xlsxwriter #Creating the Excel file for staff workbook = xlsxwriter.Workbook('test.xlsx') worksheet = workbook.add_worksheet() http://xlsxwriter.readthedocs.io/

One Approach (continued) Connect to a database Submit a query to the database (test your SQL first) Print results Write results to your spreadsheet Refine your existing code (comment, reorganize, add variable, etc)

Module for Connecting to a Database Sierra uses a PostgreSQL database for many things Python module: psycopg2 I believe Polaris uses Microsoft SQL Server database Python module: pymssql

Connect to a Sierra database #!/usr/bin/env python3 """Connect to Sierra database.""" import psycopg2 import xlsxwriter conn = psycopg2.connect("dbname='iii' user='' host='' port='' password='' sslmode='require'") https://wiki.postgresql.org/wiki/Psycopg2_Tutorial

Python: Modules/Packages Anaconda already includes many useful packages Example error when a necessary package is not installed: C:\Users\gemst\Documents\IUG2018\WeeklyNew>python weeklynew.py Traceback (most recent call last): File "weeklynew.py", line 10, in <module> import psycopg2 ImportError: No module named 'psycopg2'

Python: Installing Modules/Packages python -m pip install psycopg2 https://docs.python.org/3/installing/

Python: Installing Modules/Packages OR conda search psycopg2 conda install psycopg2 (https://conda.io/docs/using/pkgs.html)

Python: Installing Modules/Packages Collecting psycopg2 Downloading psycopg2-2.7.1-cp35-cp35m- win_amd64.whl (939kB) 100% |################################| 942kB 884kB/s Installing collected packages: psycopg2 Successfully installed psycopg2-2.7.1

Writing Your Query (Sierra focus) SQL Currently recommended when creating reports CANNOT modify data (no create, delete, or update) Some data doesn’t live in the PostgreSQL database Sierra APIs Actively being developed but currently has some significant gaps Results are currently significantly slower than SQL CAN Create, Update, and Delete selected data Create List is designed as a standalone tool and will not work well for automating reports

One Approach (continued) Create an email Send the email Refine your existing code (comment, reorganize, add variable, etc)

One Approach (continued) Create a Windows bat file that can run your Python program Use Task Scheduler to schedule your bat file to run automatically

weeklynew.bat (example) @echo off "C:\pythonw.exe" "C:\Users\gemst\weeklynew.py" Python Location Your Program Location Figure out where Python is installed Open cmd Type where python

Automating: Task Scheduler Click Windows icon and search for Task Scheduler Under Actions choose Create Task Provide a name Click the Triggers tab and New to choose the schedule (make sure Enabled is checked) Click the Actions tab and choose New Action is Start a program Browse to where you bat file is stored Start in should include the path to your program

Programming Tips Start with a goal but do little bits at a time Google your error messages (results from Stack Overflow are particular good) Double check sample code matches your Python version Don’t try to be perfect Ask for help Be persistent

Additional Resources and Troubleshooting Python Crash Course by Eric Matthes My favorite Python book so far Google Stack Overflow https://stackoverflow.com/ One of the best places to find answers to programming questions

Contact Information Gem Stone-Logan gem.stone-logan@mountainview.gov Technology Librarian Mountain View Public Library Mountain View, CA Slides: www.gemstonelogan.com/presentations.html