Slide 1

Slide 1 text

Wesley Kambale @weskambale kambale.dev Automation and Integration using Python

Slide 2

Slide 2 text

• Machine Learning Engineer with 3 years of experience • Community Builder for 3 years • Explore ML Facilitator with Crowdsource by Google for 2 years • Consultant at The Innovation Village • Google Dev Library Contributor Profile Interests Experience • Research in TinyML, TTS & LLM

Slide 3

Slide 3 text

Automation & Integration… What about Automation & Integration? ● Manual tasks ● Merging systems or apps ● Time is saved, errors are minimized, and productivity is significantly improved

Slide 4

Slide 4 text

Common Use What are the use cases? ● Automating data backups and file synchronization ● Automating repetitive data entry tasks ● Scraping data from websites for analysis or monitoring ● Integrating different systems or applications to exchange data

Slide 5

Slide 5 text

Common Use - Cont’d What are the use cases? ● Automating report generation and data analysis ● Interacting with APIs to fetch data from external services ● Automating database operations and data processing ● Monitoring and alerting systems based on predefined conditions

Slide 6

Slide 6 text

Libraries used What are the Python libraries? ● os and shutil: These libraries provide functions for automating file operations like moving, copying, renaming, and deleting files. ● selenium: This library is used for browser automation, allowing you to control web browsers programmatically and perform actions like filling forms, clicking buttons, and scraping dynamic web content.

Slide 7

Slide 7 text

Libraries used - cont’d What are the Python libraries? ● pandas: This library is widely used for data manipulation and analysis. It can help automate tasks involving data processing and generating reports ● pyodbc and sqlite3: These libraries enable database integration, allowing you to connect to databases, execute queries, and automate data operations

Slide 8

Slide 8 text

Automating File Operations How do you automate file operations? ● The os and shutil libraries for automating file operations ● The copytree() function copies the entire directories

Slide 9

Slide 9 text

import shutil
 
 # Define the source & destination paths
 source_directory = '/path/to/source'
 destination_directory = '/path/to/destination'
 
 shutil.copytree(source_directory, destination_directory)
 
 


Slide 10

Slide 10 text

Web Scraping How do you automate web scraping? ● requests and beautifulsoup4 libraries ● BS4 sends a HTTP GET requests

Slide 11

Slide 11 text

import requests
 from bs4 import BeautifulSoup
 
 url = 'https://example.com'
 
 response = requests.get(url)
 soup = BeautifulSoup(response.text, 'html.parser')
 
 title = soup.title.text
 paragraphs = soup.find_all('p')
 
 print('Title:', title)
 print('Paragraphs:')
 for p in paragraphs:
 print(p.text)
 


Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Interacting with APIs Automation in APIs ● requests library interacts with web APIs ● This library sends an HTTP GET request to a publicly available API, and acquire the response as JSON data.

Slide 14

Slide 14 text

import requests
 
 url = 'https://api.example.com/data'
 
 response = requests.get(url)
 data = response.json()
 
 # Process the data
 for item in data:
 print(item['name'], item['value'])
 


Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Database Integration Integrating databases in Python ● pyodbc and sqlite3 are used for integrating with databases ● connect() function, execute a SELECT query using the execute method, retrieve the results using the fetchall method, and then process the retrieved data

Slide 17

Slide 17 text

import sqlite3
 
 connection = sqlite3.connect('example.db')
 cursor = connection.cursor()
 
 cursor.execute('SELECT * FROM users')
 
 results = cursor.fetchall()
 
 for row in results:
 print(row)
 
 cursor.close()
 connection.close()


Slide 18

Slide 18 text

Creating Automated Reports Automated Reports in Python ● pandas is used for data manipulation and analysis, making it helpful for creating automated reports ● The read_csv() function reads data from a CSV file. Then use various functions and methods to perform calculations on the data and generate a report

Slide 19

Slide 19 text

import pandas as pd
 
 data = pd.read_csv('data.csv')
 
 total_sales = data['sales'].sum()
 average_sales = data['sales'].mean()
 
 report = f'Total sales: {total_sales}\nAverage sales: {average_sales}'
 print(report)


Slide 20

Slide 20 text

Automated Emails Sending Automated Emails in Python ● smtplib, csv, ssl are some of the libraries that we use

Slide 21

Slide 21 text

import smtplib
 from email.mime.text import MIMEText 
 from email.mime.multipart import MIMEMultipart
 
 username = 'your_email_address'
 password = 'your_email_password'
 
 message = MIMEMultipart()
 message['From'] = username
 message['Subject'] = 'Subject line'
 
 body = 'Body of the email'
 message.attach(MIMEText(body, 'plain'))
 
 to_emails = ['[email protected]', '[email protected]']


Slide 22

Slide 22 text

Read more… Blog: https://kambale.dev Article: https://kambale.dev/automation-and-integration-using-python

Slide 23

Slide 23 text

Wesley Kambale @weskambale kambale.dev Thank you! Any questions?