The main.py
script demonstrates how to send an email using Gmail's SMTP server securely. The script utilizes the smtplib
library for SMTP communication and the ssl
library for creating a secure context.
-
Import Libraries
โถ๏ธ - Imports necessary libraries such as
sys
,ssl
,smtplib
,EmailMessage
, and the customhelpers
module.
- Imports necessary libraries such as
-
Set Email Configuration ๐ง
- Sets up the email configuration, including the sender's email address (
emailSender
), receiver's email address (emailReceiver
), subject of the email (subject
), and the email body (body
).
- Sets up the email configuration, including the sender's email address (
-
Read App Password ๐
- Reads the Gmail app password from the
config.json
file using thereadJson
function from the customhelpers
module.
- Reads the Gmail app password from the
-
Compose Email โ๏ธ
- Creates an instance of the
EmailMessage
class and sets its properties, including sender, receiver, subject, and body.
- Creates an instance of the
-
Secure Connection ๐
- Establishes a secure connection to Gmail's SMTP server using the
smtplib.SMTP_SSL
class.
- Establishes a secure connection to Gmail's SMTP server using the
-
Login to Email Account ๐
- Logs in to the sender's Gmail account using the provided email address (
emailSender
) and app password (emailPassword
).
- Logs in to the sender's Gmail account using the provided email address (
-
Send Email ๐ซ
- Sends the composed email using the
smtp.sendmail
method.
- Sends the composed email using the
-
Print Success Message โ
- Prints "Email sent successfully!" to the console if the email is sent without errors.
- Update the script with your Gmail sender email address, receiver email address, and Gmail app password.
- Run the script using
python main.py
. - Check the console for the success message.
The replaceWord
function demonstrates a simple word replacement mechanism in a string.
-
Initialize String ๐
- Initializes a string with the content "Anjasfedo hi hi hi hi hi".
-
Get User Input for Word Replacement โจ๏ธ
- Takes user input for the word to be replaced using the
input
function.
- Takes user input for the word to be replaced using the
-
Get User Input for Word Replacement โจ๏ธ
- Takes user input for the replacement word using the
input
function.
- Takes user input for the replacement word using the
-
Replace Word in String ๐
- Uses the
replace
method to replace occurrences of the specified word with the replacement word in the string.
- Uses the
-
Return Modified String โก๏ธ
- Returns the modified string after the word replacement.
-
Print Modified String ๐
- Prints the result of the
replaceWord
function, showcasing the string after word replacement.
- Prints the result of the
- Modify the initial string or run the function as is to see the word replacement in action.
The arithmeticOperation
module contains functions for basic arithmetic operations.
-
Addition โ
- Adds two numbers and prints the result.
-
Subtraction โ
- Subtracts the second number from the first and prints the result.
-
Multiplication โ๏ธ
- Multiplies two numbers and prints the result.
-
Division โ
- Divides the first number by the second (with error handling for division by zero) and prints the result or an error message.
- Modify the numbers in the function calls or run the functions as is to perform basic arithmetic operations.
The main.py
script slices an email address into its components, including the username, domain, and extension.
-
Display Welcome Message ๐
- Displays a welcome message and instructions to close the program.
-
User Input for Email Address โจ๏ธ
- Takes user input for the email address.
-
Slice Email Components โ๏ธ
- Slices the email address into username, domain, and extension.
-
Print Sliced Components ๐
- Prints the sliced components of the email address.
- Run the script using
python main.py
. - Input your email address when prompted.
- View the sliced components displayed on the console.
The binarySearch
function demonstrates a binary search algorithm to find an element in a sorted list.
-
Binary Search Function :arrow_binary:
- The main binary search function that takes a sorted list (
myList
) and an element to search for (element
).
- The main binary search function that takes a sorted list (
-
Initialize variables ๐ข
middle
,start
, andend
represent indices, andsteps
counts the iterations.
-
Iterate while the search range is valid ๐
- The while loop continues until the start index is greater than the end index.
-
Display the current search range ๐
- Prints the current sub-list being considered in each iteration.
-
Update step count and calculate middle index ๐ข
- Increments the step count and calculates the middle index of the current range.
-
Check if the element is found โ
- Compares the middle element with the target element and returns the index if found.
-
Update the start and end based on element comparison ๐
- If the target element is less than the middle, updates the end index; if greater, updates the start index.
-
If the element is not found
โ ๏ธ - Prints a message indicating that the element is not present in the list.
- Calls the
binarySearch
function with an example list and element and prints the result. - Run the script using
python main.py
.
The main.py
script implements a simple quiz program using questions stored in the questions.py
module.
-
Quiz Loop ๐
- Iterates through each question in the quiz.
-
Display Question ๐ฌ
- Prints the current question.
-
User Input for Answer โจ๏ธ
- Takes user input for the answer.
-
Check Answer โ
- Compares the user's answer with the correct answer.
-
Score Tracking ๐ข
- Updates the user's score based on correct answers.
-
Display Results ๐
- Prints whether each answer is correct or wrong.
- Displays the final score at the end of the quiz.
- Run the script using
python main.py
. - Answer each quiz question prompted.
- View the correctness of your answers and your final score at the end.
The main.py
script generates a QR code for a given URL using the qrcode
library.
-
Import Libraries
โถ๏ธ - Imports necessary libraries, including
qrcode
andos
.
- Imports necessary libraries, including
-
Generate QR Code :barcode:
- Utilizes the
qrcode
library to create a QR code for a given URL. - The
os
library is used to handle directory operations.
- Utilizes the
-
Save QR Code Image ๐พ
- The generated QR code image is saved in the
images
directory. - The directory is created if it doesn't exist.
- The generated QR code image is saved in the
-
Display Image Path ๐
- Prints the path where the QR code image is saved.
- Run the script using
python main.py
. - Enter the URL when prompted.
- Check the
images
directory for the saved QR code image.
The main.py
script calculates the monthly payment for a loan based on the loan amount, annual interest rate, and the number of years.
-
Display Welcome Message ๐
- Displays a welcome message introducing the monthly payment loan calculator.
-
User Input for Loan Details โจ๏ธ
- Takes user input for the loan amount, annual interest rate, and the number of years.
-
Calculate Monthly Interest Rate ๐ข
- Calculates the monthly interest rate based on the annual interest rate.
-
Calculate Total Number of Months ๐
- Calculates the total number of months for the loan based on the number of years.
-
Calculate Monthly Payment ๐ธ
- Uses the loan formula to calculate the monthly payment.
-
Display Monthly Payment ๐ป
- Prints the calculated monthly payment with 2 decimal places on the console.
-
Save Result to Text File ๐พ
- Saves the calculated monthly payment to a text file named "interest_payment_calculator_result.txt" inside the "texts" directory.
- Run the script using
python main.py
. - Input the loan amount, annual interest rate, and the number of years when prompted.
- View the calculated monthly payment on the console.
- Check the "texts/interest_payment_calculator_result.txt" file for the saved result.
The password_generator.py
script generates a random password based on user input and saves it to a text file.
-
Generate Password ๐
- Asks the user for the desired length of the password.
- Creates a random password using a combination of uppercase letters, lowercase letters, digits, and special characters.
- Shuffles the characters to add randomness to the password.
- Displays the generated password on the console.
-
Save Password to Text File ๐พ
- Saves the generated password to a text file named "password.txt" in the "texts" directory.
- Creates the "texts" directory if it doesn't exist.
-
User Interaction ๐ป
- Asks the user if they want to generate a password.
- Ends the program if the user chooses not to generate a password.
- Run the script using
python main.py
. - Input the desired length of the password when prompted.
- View the generated password on the console.
- Check the "texts" directory for the saved password in the "password.txt" file.
The main.py
script simulates rolling two six-sided dice and displays the results using ASCII art.
-
Dice Representation ๐จ
- Defines ASCII art representations for each possible face of a six-sided die.
- ASCII art is stored in a dictionary (
diceDrawing
) with keys representing the numbers 1 to 6.
-
Roll Dice Function ๐ฒ
- Prompts the user if they want to roll the dice.
- Continues rolling as long as the user responds with 'Yes'.
- Generates random numbers for two dice rolls.
- Displays the result of the dice rolls and the corresponding ASCII art.
- Prompts the user if they want to roll again.
-
Random Number Generation ๐ฒ
- Utilizes the
random
module to generate random numbers for dice rolls.
- Utilizes the
- Run the script using
python main.py
. - Input 'Yes' when prompted to roll the dice.
- View the results of the dice rolls and corresponding ASCII art.
- Choose to roll again or end the program.
The main.py
script checks the connectivity of a specified website by attempting to open a connection to the provided URL.
-
Main Function ๐
- Defines a function named
main
that takes a URL as a parameter. - Opens a connection to the specified URL using
urllib.urlopen
. - Displays a message indicating successful connection along with the response code.
- Defines a function named
-
Site Connectivity Check ๐
- Prompts the user to input the domain of the site (e.g., "google.com").
- Constructs a full URL by adding "https://www." as a prefix to the user-provided domain.
- Calls the
main
function, passing the constructed full URL, to check the site's connectivity.
- Run the script using
python main.py
. - Input the domain of the site when prompted.
- View the messages indicating the site's connectivity and response code.
The main.py
script converts US dollars to Pound Sterling using a fixed exchange rate.
-
Main Function ๐ธ
- Defines a function named
main
. - Displays a message indicating the purpose of the script.
- Prompts the user to input a dollar amount using
eval
to evaluate the input as a Python expression. - Calls the
convert_to_pounds
function to convert dollars to pounds. - Displays the result of the conversion.
- Defines a function named
-
Conversion Function ๐ฑ
- Uses a lambda function named
convert_to_pounds
to convert dollars to pounds using a fixed exchange rate.
- Uses a lambda function named
- Run the script using
python main.py
. - Input the dollar amount when prompted.
- View the converted amount in pounds sterling.
The is_leap_year
function checks if a given year is a leap year or not.
- Leap Year Checking ๐
- The function takes a
year
as an argument. - Checks if the year is divisible by 4.
- If divisible by 4, it further checks if it is divisible by 100.
- If divisible by 100, it checks if it is divisible by 400.
- If divisible by 400, prints "Leap year."
- If not divisible by 400, prints "Not leap year."
- If not divisible by 100, prints "Leap year."
- If divisible by 100, it checks if it is divisible by 400.
- If not divisible by 4, prints "Not leap year."
- The function takes a
- Call the function
is_leap_year
with the desired year as an argument.is_leap_year(2000)
- The function will print whether the given year is a leap year or not. Example Output: "Leap year" (for the year 2000)
The script utilizes the PyDictionary
library to retrieve the meaning of a given word.
-
Import PyDictionary ๐
- Imports the
PyDictionary
class from thePyDictionary
module.
- Imports the
-
Create PyDictionary Instance ๐ญ
- Creates an instance of the
PyDictionary
class nameddictionaries
.
- Creates an instance of the
-
Input Loop ๐
- Initiates an infinite loop using
while True
.
- Initiates an infinite loop using
-
User Input for Word โจ๏ธ
- Prompts the user to enter a word.
-
Check for Empty Input โ
- Checks if the entered word is an empty string.
- If empty, exits the loop.
- Checks if the entered word is an empty string.
-
Retrieve and Display Meaning ๐
- Uses the
meaning
method of thePyDictionary
class to retrieve the meaning of the entered word. - Prints the meaning to the console.
- Uses the
- Run the script and input a word when prompted.
- View the meaning of the entered word on the console.
- To exit the loop, simply press Enter without typing a word.
The readJson
function serves as a helper to read values from a JSON configuration file.
-
Read JSON Configuration ๐
- Takes two parameters:
path
for the path to the JSON file andvalue
for the key to retrieve. - Uses the
open
function to open the specified JSON file in read mode. - Utilizes
json.load
to load the JSON content from the file.
- Takes two parameters:
-
Retrieve Specific Value โก๏ธ
- Returns the value associated with the specified key (
value
) in the JSON file.
- Returns the value associated with the specified key (
-
Error Handling
โ ๏ธ - The function assumes that the key (
value
) exists in the JSON file. Error handling can be added to handle cases where the key is not present.
- The function assumes that the key (
-
Configure JSON File โ๏ธ
- Ensure that the
config.json
file is properly configured with the required key-value pairs. For example:{ "GMAIL_APP_PASSWORD": "your_gmail_app_password" }
- Ensure that the
-
Use
readJson
Function ๐ฒ-
Call the
readJson
function in your main script to retrieve specific values from the configuration file.# Example usage in the main script email_password = readJson("path/to/config.json", "GMAIL_APP_PASSWORD")
-