Converter
Converter module for dost. This module contains functions to convert between different data types.
Examples:
>>> from dost import converter
>>> converter.csv_to_excel(input_filepath='tests\demo.csv', output_folder='tests')
>>> converter.base64_to_image(input_filepath='tests\demo.txt')
>>> converter.image_to_base64(input_filepath='tests\demo.png', output_folder='tests')
>>> converter.jpg_to_png(input_filepath='tests\demo.jpg', output_folder='tests')
>>> converter.png_to_jpg(input_filepath='tests\demo.png', output_folder='tests')
>>> converter.excel_to_html(input_filepath='tests\demo.xlsx', output_folder='tests')
The module contains the following functions:
csv_to_excel(input_filepath, output_folder, output_filename, contains_headers, sep)
: Convert a CSV file to an Excel file.excel_to_html(input_filepath, output_folder, output_filename)
: Convert an Excel file to an HTML file.image_to_base64(input_filepath)
: Convert an image to a base64 string.base64_to_image(input_text, output_folder, output_filename)
: Convert a base64 string to an image.jpg_to_png(input_filepath, output_folder, output_filename)
: Convert a JPG image to a PNG image.png_to_jpg(input_filepath, output_folder, output_filename)
: Convert a PNG image to a JPG image.
base64_to_image(input_text, output_folder, output_filename='')
Get an image from a base64 encoded string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_text |
str
|
The base64 encoded string. |
required |
output_folder |
str || WindowsPath
|
The path to the output folder. |
required |
output_filename |
str default ending with .png
|
The name of the output file. |
''
|
Examples:
csv_to_excel(input_filepath, output_folder, output_filename='', contains_headers=True, sep=',')
Convert a CSV file to an Excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_filepath |
str || WindowsPath
|
The path to the CSV file. |
required |
output_folder |
str || WindowsPath
|
The path to the output folder. |
required |
output_filename |
str
|
The name of the output file. |
''
|
contains_headers |
bool
|
Whether the CSV file contains headers. |
True
|
sep |
str
|
The separator used in the CSV file. |
','
|
Examples:
excel_to_html(input_filepath, output_folder, output_filename='')
Converts the excel file to colored html file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_filepath |
str || WindowsPath
|
Input excel file path |
required |
output_folder |
str || WindowsPath
|
Output folder path |
required |
output_filename |
str
|
Output file name |
''
|
Examples:
image_to_base64(input_filepath)
jpg_to_png(input_filepath, output_folder, output_filename='')
Convert a JPG image to a PNG image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_filepath |
str || WindowsPath
|
The path to the JPG image. |
required |
output_folder |
str || WindowsPath
|
The path to the output folder. |
required |
output_filename |
str
|
The name of the output file. |
''
|
Examples:
png_to_jpg(input_filepath, output_folder, output_filename='')
Converts the image from png to jpg format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_filepath |
str || WindowsPath
|
Input image file path |
required |
output_folder |
str || WindowsPath
|
Output folder path |
required |
output_filename |
str
|
Output file name |
''
|
Examples: