A collection of Python Scripts I wrote for the Google Automation certificate: link
This script is used to convert TIFF images to JPEG format in a specified directory.
- Place the script file (
convert_images.py
) in the desired directory. - Create a subdirectory named
supplier-data
in the same directory. - Inside the
supplier-data
directory, create animages
subdirectory and place the TIFF images to be converted inside it. - Open a terminal or command prompt and navigate to the directory containing the script.
- Run the following command to execute the script:
- The script will search for TIFF images in the
./supplier-data/images/
directory and convert them to JPEG format. - The converted JPEG images will be saved with the same filename but with the extension changed to
.jpeg
in the same directory.
This script provides a simple interface to send emails with attachments using the SMTP protocol.
-
Ensure that you have the necessary email server settings configured. By default, the script assumes that the email server is running on
localhost
. If you are using a different email server, update themail_server
variable in thesend()
method accordingly. -
Import the script into your Python project:
-
Create an email message using the
Email
class constructor:email = Email(sender, recipient, subject, body)
sender
: Email address of the sender.recipient
: Email address of the recipient.subject
: Subject of the email.body
: Content of the email.
-
Add an attachment (optional) using the
add_attachment()
method:email.add_attachment(attachment_path)
attachment_path
: Path to the file to be attached.
-
Send the email using the
send()
method:email.send()
This script performs a health check on the system by monitoring disk usage, CPU usage, memory availability, and hostname resolution. It sends email notifications if any of the monitored metrics exceed predefined thresholds or if there are errors in hostname resolution.
- Python 3
psutil
module (install usingpip install psutil
)emails
module (install usingpip install emails
)
Before running the script, make sure to configure the following variables within the script:
sender
: Email address of the sender.receiver
: Email address of the recipient. By default, it uses the current user's username obtained from the environment variables.body
: Body of the email notification to be sent.
-
Ensure that the required modules (
psutil
andemails
) are installed. -
The script will perform the following checks:
- Disk Usage: Checks if the available disk space is less than 20% and sends an email notification if it is.
- CPU Usage: Checks if the CPU usage is over 80% and sends an email notification if it is.
- Memory Availability: Checks if the available memory is less than 500MB and sends an email notification if it is.
- Hostname Resolution: Checks if the hostname 'localhost' can be resolved to '127.0.0.1' and sends an email notification if it cannot.
Note: You can customize the threshold values and error messages for each check within their respective functions.
-
The script will send email notifications using the
emails
module if any of the checks fail or encounter errors.