The simple_commands library is a Python library designed to help reduce the time required to write code.
With a collection of commands, this library is ideal for Python developers.
who want to increase work efficiency and reduce time spent writing repetitive code
simple_commands library It contains many commands such as
Commands for managing files and folders.
Command for taking pictures
Command for creating an image with an existing image.
Instructions for retrieving time by country
instructions for math
Commands for other general tasks
This library is easy to use. Just import the library and run the required commands. The library will execute that command immediately.
How to use and commands are as follows:
Fetch the library:
import simple_commands
When you import simple_commands, you normally have to write module_name.function_name to use functions from the module. However
if you use from simple_commands import function, you can use the functions directly without specifying the module name.
Example of library use simple_commands About the file:
main_folder(main_folder_path, file_type=None): Searches files in main folder and subfolders and returns a list of files.
main_folder_path: The path to the main folder you want to search.
file_type: The type of file you want to search for. (Default is None, to search for image files use 'img')
folder_file(path, file_type=None): Searches for files in the specified folder and returns a list of files.
path: The path to the folder you want to search.
file_type: The type of file you want to search for. (Default is None, to search for image files use '.img')
list_files_in_current_directory(): List of files in the current directory.
create_new_directory(directory_name): Create a new folder.
directory_name: The name of the folder you want to create.
move_file(source_path, destination_path): Move file from specified path to destination path.
source_path: Path to the source file you want to move.
destination_path: The path to the destination location you want to move to.
delete_directory(directory_path): Delete a folder and its contents.
directory_path: Path to the folder you want to delete.
Example of library usage simple_commands About the image:
load_images(image_path):
image_path: The address of the image to be loaded
Note: Every function related to images must pass through load_images
gray_image(image, path=None, name=None):
image: The image to be converted to grayscale
path: (Optional) The path to store the grayscale image file (if you want to save it)
name: (Optional) The name of the grayscale image file (if you want to save it)
new_data_image(image, output_dir, base_name=None):
image: The image you want to create a new image from (by rotating the original image)
output_dir: The folder to save the new image
base_name: (Optional) The base name for the new image file
use_PIL(image):
image: The image you want to convert to the PIL Image format
show(name, image, waitKey='q'):
name: The name of the window displaying the image
image: The image to be displayed
waitKey: (Optional) The key used to wait for the user to close the window (default is 'q')
adjust_img_color(image, number_new=1, color_value=0.5, color_value_end=1.5):
image: The image you want to adjust the color of
number_new: (Optional) The number of new images to generate by adjusting the color (default is 1)
color_value: (Optional) The starting color value for color adjustment (default is 0.5)
color_value_end: (Optional) The ending color value for color adjustment (default is 1.5)
resize(image, size):
image: The image you want to resize
size: The size you want for the new image (a tuple with two values: width and height)
save(name, file):
name (str): Name of the file to save.
file: Array of images to save.
Statement:
If the recording is successful The function returns True and there are no errors.
If recording fails The function returns False and details the error.
Example of library usage simple_commands About the database:
# Create a Database object
db = Database('my_database.db')
# Create a table
db.create_table('my_table', ['id INTEGER PRIMARY KEY', 'name TEXT', 'age INTEGER'])
# Insert data
db.insert_data('my_table', (1, 'Alice', 30))
db.insert_data('my_table', (2, 'Bob', 25))
# Retrieve all data
all_data = db.select_all_data('my_table')
for row in all_data:
print(row)
# Retrieve specific columns
selected_data = db.select_data(['name', 'age'], 'my_table')
for row in selected_data:
print(row)
# Update data
update_values = {'age': 31}
where_clause = 'id = 1'
db.update_data('my_table', update_values, where_clause)
# Delete data
delete_where_clause = 'id = 2'
db.delete_data('my_table', delete_where_clause)
# After using the database, it's a good practice to disconnect
db.disconnect()
Example of library usage simple_commands About time zones:
# Create a Time_zone object by specifying the desired time zone (e.g., "Asia/Bangkok")
my_timezone = Time_zone("Asia/Bangkok")
# Call the get_current_time method to retrieve the current time in the specified time zone
current_time = my_timezone.get_current_time()
print("Current time in the specified time zone:", current_time)
# Set a source_time
source
_time = datetime.datetime(2023, 9, 7, 12, 0, 0, tzinfo=pytz.timezone("UTC"))
# Call the convert_time method to convert source_time to "Asia/Bangkok" time zone
target_timezone_name = "Asia/Bangkok"
target_time = my_timezone.convert_time(source_time, target_timezone_name)
print("Time in the", target_timezone_name, "time zone is:", target_time)
# Call the add_hours method to add 2 hours to source_time
new_time = my_timezone.add_hours(source_time, 2)
print("Time after adding 2 hours:", new_time)
# Call the subtract_minutes method to subtract 30 minutes from source_time
new_time = my_timezone.subtract_minutes(source_time, 30)
print("Time after subtracting 30 minutes:", new_time)
# Call the time_difference method to calculate the time difference between current_time and target_time
time_diff = my_timezone.time_difference(current_time, target_time)
print("Time difference between current time and time in", target_timezone_name, "is:", time_diff)
Example of library usage simple_commands About math:
calculate_triangle_area(base, height): Calculate the area of a triangle. It takes the length of the base (base) and height (height) and returns the area.
calculate_rectangle_area(length, width): Calculate the area of a rectangle. It takes the length (length) and width (width) and returns the area.
calculate_square_area(side): Calculate the area of a square. It takes the length of the side (side) and returns the area.
calculate_circle_area(radius): Calculate the area of a circle. It takes the radius (radius) and returns the area using the value π (pi).
calculate_triangle_perimeter(side1, side2, side3): Calculate the perimeter of a triangle. It takes the lengths of three sides (side1, side2, side3) and returns the perimeter of the triangle.
calculate_rectangle_perimeter(length, width): Calculate the perimeter of a rectangle. It takes the length (length) and width (width) and returns the perimeter.
calculate_square_perimeter(side): Calculate the perimeter length of a square. It takes the length of the side (side) and returns the perimeter.
calculate_circle_circumference(radius): Calculate the circumference length of a circle. It takes the radius (radius) and returns the length around the circle using the value π (pi).
calculate_cone_volume(radius, height): Calculate the volume of a cone. It takes the base radius (radius) and height (height) and returns the volume of the cone.
calculate_cylinder_volume(radius, height): Calculate the volume of a cylinder. It takes the base radius (radius) and height (height) and returns the volume of the cylinder.
calculate_oxygen_cylinder_volume(diameter, height): Calculates the volume of an oxygen cylinder. It takes the diameter (diameter) and height (height) and returns the volume of the oxidian cylinder.
tempFtoC(F): Convert temperature from Fahrenheit to Celsius.
tempCtoF(C): Convert temperature from Celsius to Fahrenheit.
Example of library usage simple_commands About password:
"""The length of the password must be 6 characters or more."""
generate_random_password(length=12, use_uppercase=True, use_digits=True, use_symbols=True)
length (default is 12): The length parameter specifies the desired length of the password to generate. The default value is 12 characters.
use_uppercase (default is True): The use_uppercase parameter determines whether to include uppercase letters in the password or not. If set to True, it will include uppercase letters, and if set to False, it will not.
use_digits (default is True): The use_digits parameter specifies whether to include digits in the password or not. If set to True, it will include digits, and if set to False, it will not.
use_symbols (default is True): The use_symbols parameter indicates whether to include symbols (special characters) in the password or not. If set to True, it will include symbols, and if set to False, it will not.
generate_random_password(length=12, use_uppercase=True, use_digits=True, use_symbols=True):
The main function used to generate a random password.
length: The desired length of the password (default is 12).
use_uppercase: Specifies whether the password should include uppercase letters (default is True).
use_digits: Specifies whether the password should include digits (default is True).
use_symbols: Specifies whether the password should include special symbols (default is True).
This function randomly selects characters based on the settings and length provided, then generates a random password.
generate_random_password_with_uppercase(length=12):
A function used to generate a password consisting of uppercase letters only.
length: The desired length of the password (default is 12).
generate_random_password_with_digits(length=12):
A function used to generate a password consisting of digits only.
length: The desired length of the password (default is 12).
generate_random_password_with_symbols(length=12):
A function used to generate a password consisting of special symbols only.
length: The desired length of the password (default is 12).
Example of library usage simple_commands About saving data:
Retrieve_log(name, path, type="txt"): This function is used to copy a log file from the loal(name,type) location and paste it into the path.
create_log(name, type="txt"): This function is used to create a new log file. It uses the 'x' mode, which creates a new file only if the file doesn't already exist. If the function is called and the file exists, it returns None without creating a new file.
adddata_to_log(name, text, type="txt"): This function is used to append data to a log file. It opens the file in 'a' mode to write data at the end of the log file.
delete_log(name, type="txt"): This function is used to delete a log file. It moves the deleted file to the deletedata folder and records information about the deletion in an SQLite database.
recover_log(name, type="txt"): This function is used to recover a deleted log file. It checks the time when the file was deleted and, if the deletion occurred less than 30 days ago, it either retrieves the file from the deletedata folder or moves it back to the savedata folder.
list_log(name=None, type="txt"): This function is used to list the log files in the savedata folder or in a folder specified by name (if provided) and returns a list of those files.
list_log_delete(name, type="txt"): This function is used to list the log files in the deletedata folder or in a folder specified by name (if provided) and returns a list of those files.
return_data_log(name, type="txt"): This function is used to read data from a log file and returns the data as a string.
delete_text_in_log(name, text_to_delete, type="txt"): This function is used to delete specific text within a log file. It reads all data from the log file, searches and removes the text specified by the user, and then writes the modified data back to the log file, excluding the deleted text.
delete_alltext_log(name, type="txt"): This function is used to delete all text content within a log file. It overwrites the log file with an empty file, effectively clearing all its contents.