[<img src="https://raw.githubusercontent.com/Kaviyes/kaviyesutil/37c00cd0806a99bded88d82c255ae12161ffd6ef/Kaviyesutil.svg" width="385"/>](https://github.com/Kaviyes/kaviyesutil)
![Open Issues](https://img.shields.io/github/issues/Kaviyes/kaviyesutil.svg) ![Python](https://camo.githubusercontent.com/3da9491fa3fce6afca8e32177b260cb87bea5d4dbcc057da64589a94dbc5815a/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f676f6f676c652d67656e657261746976656169) ![Closed Issues](https://img.shields.io/github/issues-closed/Kaviyes/kaviyesutil.svg)
A standard kaviyes utility for python thats ideal for small projects and prototypes.
## Installation
You can install and update using [pip](https://pip.pypa.io/en/stable/getting-started/)
```
pip install kaviyesutil -U
```
## Usage
```
import kaviyes.util as util
```
## Functions and Parameters
|FUNCTION|DESCRIPTION|
|---|---|
|[`connected`](#connected)|Checks if there is an active internet connection.|
|[`reverse_string`](#reverse_string)|Reverses a given string.|
|[`timenow`](#timenow)|Returns the current time in a specified format.|
|[`delay`](#delay)|A delay function based on how many seconds.|
|[`terminal`](#terminal)|This function allows you to quickly execute any command as if you were typing it directly into the terminal.|
|[`clter`](#clter)|Clears the contents of the terminal screen|
|[`get_file_size`](#get_file_size)|Gets the size of a file in bytes.|
|[`directory_exists`](#directory_exists)|Checks if a directory exists.|
|[`file_exists`](#file_exists)|Checks if a file exists at the specified path.|
|[`writecontent`](#writecontent)|Writes content to a file, optionally appending to the file.|
|[`readcontent`](#readcontent)|Reads the content of a file and optionally strips whitespace.|
|[`respath`](#respath)|Get Absolute path to resource, works for dev and for PyInstaller|
|[`write_json`](#write_json)|Writes JSON data to a file.|
|[`read_json`](#read_json)|Reads JSON data from a file.|
<br>
## Examples
### `connected`
Parameters
- `url (str)` : URL to test the connection. Defaults to Google.
- `timeout (int)` : Timeout in seconds for the connection test. Defaults to 5.
```
util.connected(url='http://www.google.com', timeout=5):
```
OUTPUT
```
True
```
Returns
- bool : True if conneted, False otherwise,
---
### `reverse_string`
Parameters:
- `s (str)` : The string to reverse.
```
x = util.reverse_string("Hello, World!")
print(x)
```
OUTPUT
```
!dlroW ,olleH
```
Returns:
- str : The reversed string.
---
### `timenow`
Parameters:
`format (str, optional)` :
A string specifying the format in which to return the time.
If provided, this format string will be used. Common format codes include:
- `'%H:%M:%S'` for hours, minutes, and seconds in 24-hour format
- `'%I:%M:%S %p'` for hours, minutes, and seconds in 12-hour format with AM/PM
<br>
`format_24H (bool, optional)` :
A boolean that determines the time format when `format` is not provided.
- If `True`, the function uses the 24-hour format (e.g., '14:30:00').
- If `False`, the function uses the 12-hour format with AM/PM (e.g., '2:30:00 PM').
Defaults to `True`.
```
x = util.timenow()
print(x)
```
OUTPUT
```
18:00:00
```
Returns:
- str : The current time formatted according to the provided `format` string or default settings.
---
### `delay`
Parameters:
- `secs (float)` : The number of seconds to delay the execution.
```
util.delay(2.3)
```
OUTPUT
```
None
```
Returns:
- None : This function does not return any value.
---
### `terminal`
Parameters:
- `command (str)` : The command to be executed in the terminal.
```
util.terminal("echo Hello, World!")
```
OUTPUT
```
Hello, World!
```
Returns:
- None : This function does not return any value.
---
### `clter`
Parameters:
- `message (object, optional)` : An optional message to print after clearing the terminal screen.
```
util.clter()
```
OUTPUT
```
```
---
```
util.clter("Hello, World!")
```
OUTPUT
```
Hello, World!
```
Returns:
- None : This function does not return any value.
---
### `get_file_size`
Parameters:
- `file_path (str)` : Path to the file.
```
x = util.get_file_size("story.txt")
print(x)
```
OUTPUT
```
2313
```
Returns:
- int : The size of the file in bytes, or -1 if the file does not exist.
---
### `directory_exists`
Paramters:
- `directory_path (str)` : Path to the directory.
```
x = util.directory_exists("directory")
print(x)
```
OUTPUT
```
True
```
Returns:
- bool : True if directory exists, False otherwise.
---
### `file_exists`
Paramters:
- `file_path (str)` : Path to the directory.
```
x = util.file_exists("file.txt")
print(x)
```
OUTPUT
```
True
```
Returns:
- bool : True if file exists, False otherwise.
---
### `writecontent`
Parameters:
- `file_path (str)` : The path to the file to be written.
- `content (str)` : The content to write to the file.
- `append (bool)` : If True, appends to the file instead of overwriting. Defaults to False.
- `debug (bool)` : If True, prints error messages for IOError. Defaults to False.
```
x = util.writecontent("greet.txt", "Hello, World!")
print(x)
```
OUTPUT
```
True
```
Returns:
- bool : True if writing was successful, False otherwise.
---
### `readcontent`
Parameters:
- `file_path (str)` : The path to the file to be read.
- `strip_whitespace` (bool): If True, removes leading and trailing whitespace from the content. Defaults to False.
- `debug (bool)` : If True, prints error messages for FileNotFoundError or IOError. Defaults to False.
- `uppercase (bool)` : Changes every strings to uppercase.
- `lowercase (bool)` : Changes every strings to lowercase.
```
x = util.readcontent("greet.txt")
print(x)
```
OUTPUT
```
Hello, World!
```
Returns:
- str or None: The content of the file, or None if an error occurs.
---
### `respath`
Parameters:
- `relative_path (str)` : The relative path to the resource. This should be a path relative to the directory where the script is running or the bundled application's directory.
```
x = util.respath("banana.png")
print(x)
```
OUTPUT
```
K:\Application\assets\banana.png
```
Returns:
- str: The absolute path to the resource.
---
### `write_json`
Parameters:
- `file_path (str)`: Path to the JSON file.
- `data (dict)`: The data to write to the file.
- `debug (bool)`: If True, prints error messages for IOError. Defaults to False.
```
data = {"name:": "John", "age": 23, "country": "Germany"}
x = util.write_json("ID.json", data)
print(x)
```
OUTPUT
```
True
```
Returns:
- bool: True if writing was successful, False otherwise.
---
### `read_json`
Parameters:
- `file_path (str)`: Path to the JSON file.
- `debug (bool)`: If True, prints error messages for FileNotFoundError or JSONDecodeError. Defaults to False.
```
x = util.read_json("ID.json")
print(x)
```
OUTPUT
```
{'name:': 'John', 'age': 23, 'country': 'Germany'}
```
Returns:
- dict or None: The parsed JSON data as a dictionary, or None if an error occurs
---
<br><br>
## Compatibility support
The kaviyesutil version **2.1.2** is not compatible with the older versions. The version **2.0.1** is usable with:
```
import kaviyes.util.legacy as util
```
## Changelog 2.1.1
* Improved overall readability of the documentations and functions.
* Minor improvements.
* Added basic file management utilities.
## Requirements:
Python version: **3.9** minimum
IDE:
* Visual Studio Code (Fully compatible)
* PyCharm & Visual Studio (Function description is displayed in raw but still readable)
OS:
* Linux
* Windows (8.1 and later)
* macOS (10.15 Catalina and later)
Links:
* [PyPi](https://pypi.org/project/kaviyesutil/)
* Found a problem [create an issue](https://github.com/Kaviyes/kaviyesutil/issues/new/choose) here!
* Create a [pull request](https://github.com/Kaviyes/kaviyesutil/compare) here!
<br>
<br>
<br>
<br>
<p align="center">
<a href="https://github.com/Kaviyes/">
<img src="https://raw.githubusercontent.com/Kaviyes/kaviyesutil/main/Kaviyes-Text.png" alt="KAVIYES" width="500"/>
</a>
</p>
<br>
Raw data
{
"_id": null,
"home_page": "https://github.com/Kaviyes/kaviyesutil",
"name": "kaviyesutil",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "utility, toolkit",
"author": "Kaviyes",
"author_email": "contact.karlvince@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4f/10/3d89182228866d9c971786ae8e8c7b0341a09d41b0de77d063dcd75fc510/kaviyesutil-2.1.2.tar.gz",
"platform": null,
"description": "[<img src=\"https://raw.githubusercontent.com/Kaviyes/kaviyesutil/37c00cd0806a99bded88d82c255ae12161ffd6ef/Kaviyesutil.svg\" width=\"385\"/>](https://github.com/Kaviyes/kaviyesutil)\r\n\r\n![Open Issues](https://img.shields.io/github/issues/Kaviyes/kaviyesutil.svg) ![Python](https://camo.githubusercontent.com/3da9491fa3fce6afca8e32177b260cb87bea5d4dbcc057da64589a94dbc5815a/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f676f6f676c652d67656e657261746976656169) ![Closed Issues](https://img.shields.io/github/issues-closed/Kaviyes/kaviyesutil.svg)\r\n\r\nA standard kaviyes utility for python thats ideal for small projects and prototypes.\r\n\r\n## Installation\r\nYou can install and update using [pip](https://pip.pypa.io/en/stable/getting-started/)\r\n```\r\npip install kaviyesutil -U\r\n```\r\n\r\n## Usage\r\n```\r\nimport kaviyes.util as util\r\n```\r\n\r\n## Functions and Parameters\r\n\r\n|FUNCTION|DESCRIPTION|\r\n|---|---|\r\n|[`connected`](#connected)|Checks if there is an active internet connection.|\r\n|[`reverse_string`](#reverse_string)|Reverses a given string.|\r\n|[`timenow`](#timenow)|Returns the current time in a specified format.|\r\n|[`delay`](#delay)|A delay function based on how many seconds.|\r\n|[`terminal`](#terminal)|This function allows you to quickly execute any command as if you were typing it directly into the terminal.|\r\n|[`clter`](#clter)|Clears the contents of the terminal screen|\r\n|[`get_file_size`](#get_file_size)|Gets the size of a file in bytes.|\r\n|[`directory_exists`](#directory_exists)|Checks if a directory exists.|\r\n|[`file_exists`](#file_exists)|Checks if a file exists at the specified path.|\r\n|[`writecontent`](#writecontent)|Writes content to a file, optionally appending to the file.|\r\n|[`readcontent`](#readcontent)|Reads the content of a file and optionally strips whitespace.|\r\n|[`respath`](#respath)|Get Absolute path to resource, works for dev and for PyInstaller|\r\n|[`write_json`](#write_json)|Writes JSON data to a file.|\r\n|[`read_json`](#read_json)|Reads JSON data from a file.|\r\n\r\n<br>\r\n\r\n## Examples\r\n\r\n### `connected`\r\n\r\nParameters\r\n- `url (str)` : URL to test the connection. Defaults to Google.\r\n- `timeout (int)` : Timeout in seconds for the connection test. Defaults to 5.\r\n\r\n```\r\nutil.connected(url='http://www.google.com', timeout=5):\r\n```\r\nOUTPUT\r\n```\r\nTrue\r\n```\r\n\r\nReturns\r\n- bool : True if conneted, False otherwise,\r\n\r\n---\r\n\r\n### `reverse_string`\r\n\r\nParameters:\r\n- `s (str)` : The string to reverse.\r\n\r\n\r\n```\r\nx = util.reverse_string(\"Hello, World!\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\n!dlroW ,olleH\r\n```\r\n\r\nReturns:\r\n- str : The reversed string.\r\n\r\n---\r\n\r\n### `timenow`\r\n\r\nParameters:\r\n`format (str, optional)` :\r\n\r\nA string specifying the format in which to return the time. \r\n\r\nIf provided, this format string will be used. Common format codes include:\r\n- `'%H:%M:%S'` for hours, minutes, and seconds in 24-hour format\r\n- `'%I:%M:%S %p'` for hours, minutes, and seconds in 12-hour format with AM/PM\r\n\r\n<br>\r\n\r\n`format_24H (bool, optional)` :\r\n\r\nA boolean that determines the time format when `format` is not provided. \r\n- If `True`, the function uses the 24-hour format (e.g., '14:30:00').\r\n- If `False`, the function uses the 12-hour format with AM/PM (e.g., '2:30:00 PM'). \r\nDefaults to `True`.\r\n\r\n```\r\nx = util.timenow()\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\n18:00:00\r\n```\r\nReturns:\r\n- str : The current time formatted according to the provided `format` string or default settings.\r\n\r\n---\r\n\r\n### `delay`\r\n\r\nParameters:\r\n- `secs (float)` : The number of seconds to delay the execution.\r\n\r\n```\r\nutil.delay(2.3)\r\n```\r\nOUTPUT\r\n```\r\nNone\r\n```\r\nReturns:\r\n- None : This function does not return any value.\r\n\r\n---\r\n\r\n### `terminal`\r\n\r\nParameters:\r\n- `command (str)` : The command to be executed in the terminal.\r\n\r\n```\r\nutil.terminal(\"echo Hello, World!\")\r\n```\r\nOUTPUT\r\n```\r\nHello, World!\r\n```\r\n\r\nReturns:\r\n- None : This function does not return any value.\r\n\r\n---\r\n\r\n### `clter`\r\n\r\nParameters:\r\n- `message (object, optional)` : An optional message to print after clearing the terminal screen.\r\n\r\n```\r\nutil.clter()\r\n```\r\nOUTPUT\r\n```\r\n\r\n```\r\n---\r\n```\r\nutil.clter(\"Hello, World!\")\r\n```\r\nOUTPUT\r\n```\r\nHello, World!\r\n```\r\nReturns:\r\n- None : This function does not return any value.\r\n\r\n---\r\n\r\n### `get_file_size`\r\n\r\nParameters:\r\n- `file_path (str)` : Path to the file.\r\n\r\n```\r\nx = util.get_file_size(\"story.txt\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\n2313\r\n```\r\n\r\nReturns:\r\n- int : The size of the file in bytes, or -1 if the file does not exist.\r\n\r\n---\r\n\r\n### `directory_exists`\r\n\r\nParamters:\r\n- `directory_path (str)` : Path to the directory.\r\n\r\n```\r\nx = util.directory_exists(\"directory\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nTrue\r\n```\r\n\r\nReturns:\r\n- bool : True if directory exists, False otherwise.\r\n\r\n---\r\n\r\n### `file_exists`\r\n\r\nParamters:\r\n- `file_path (str)` : Path to the directory.\r\n\r\n```\r\nx = util.file_exists(\"file.txt\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nTrue\r\n```\r\n\r\nReturns:\r\n- bool : True if file exists, False otherwise.\r\n\r\n---\r\n\r\n### `writecontent`\r\n\r\nParameters:\r\n- `file_path (str)` : The path to the file to be written.\r\n- `content (str)` : The content to write to the file.\r\n- `append (bool)` : If True, appends to the file instead of overwriting. Defaults to False.\r\n- `debug (bool)` : If True, prints error messages for IOError. Defaults to False.\r\n\r\n```\r\nx = util.writecontent(\"greet.txt\", \"Hello, World!\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nTrue\r\n```\r\n\r\nReturns:\r\n- bool : True if writing was successful, False otherwise.\r\n\r\n---\r\n\r\n### `readcontent`\r\n\r\nParameters:\r\n- `file_path (str)` : The path to the file to be read.\r\n- `strip_whitespace` (bool): If True, removes leading and trailing whitespace from the content. Defaults to False.\r\n- `debug (bool)` : If True, prints error messages for FileNotFoundError or IOError. Defaults to False.\r\n- `uppercase (bool)` : Changes every strings to uppercase.\r\n- `lowercase (bool)` : Changes every strings to lowercase.\r\n\r\n```\r\nx = util.readcontent(\"greet.txt\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nHello, World!\r\n```\r\n\r\nReturns:\r\n- str or None: The content of the file, or None if an error occurs.\r\n\r\n---\r\n\r\n### `respath`\r\n\r\nParameters:\r\n- `relative_path (str)` : The relative path to the resource. This should be a path relative to the directory where the script is running or the bundled application's directory.\r\n\r\n```\r\nx = util.respath(\"banana.png\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nK:\\Application\\assets\\banana.png\r\n```\r\n\r\nReturns:\r\n- str: The absolute path to the resource.\r\n\r\n---\r\n\r\n### `write_json`\r\n\r\nParameters:\r\n- `file_path (str)`: Path to the JSON file.\r\n- `data (dict)`: The data to write to the file.\r\n- `debug (bool)`: If True, prints error messages for IOError. Defaults to False.\r\n\r\n```\r\ndata = {\"name:\": \"John\", \"age\": 23, \"country\": \"Germany\"}\r\nx = util.write_json(\"ID.json\", data)\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\nTrue\r\n```\r\n\r\nReturns:\r\n- bool: True if writing was successful, False otherwise.\r\n\r\n---\r\n\r\n### `read_json`\r\n\r\nParameters:\r\n- `file_path (str)`: Path to the JSON file.\r\n- `debug (bool)`: If True, prints error messages for FileNotFoundError or JSONDecodeError. Defaults to False.\r\n\r\n```\r\nx = util.read_json(\"ID.json\")\r\nprint(x)\r\n```\r\nOUTPUT\r\n```\r\n{'name:': 'John', 'age': 23, 'country': 'Germany'}\r\n```\r\n\r\nReturns:\r\n- dict or None: The parsed JSON data as a dictionary, or None if an error occurs\r\n\r\n---\r\n<br><br>\r\n\r\n## Compatibility support\r\n\r\nThe kaviyesutil version **2.1.2** is not compatible with the older versions. The version **2.0.1** is usable with:\r\n```\r\nimport kaviyes.util.legacy as util\r\n```\r\n\r\n## Changelog 2.1.1\r\n\r\n* Improved overall readability of the documentations and functions.\r\n* Minor improvements.\r\n* Added basic file management utilities.\r\n\r\n## Requirements:\r\n\r\n Python version: **3.9** minimum\r\n\r\nIDE:\r\n* Visual Studio Code (Fully compatible)\r\n* PyCharm & Visual Studio (Function description is displayed in raw but still readable)\r\n\r\nOS:\r\n* Linux\r\n* Windows (8.1 and later)\r\n* macOS (10.15 Catalina and later)\r\n\r\nLinks:\r\n* [PyPi](https://pypi.org/project/kaviyesutil/)\r\n* Found a problem [create an issue](https://github.com/Kaviyes/kaviyesutil/issues/new/choose) here!\r\n* Create a [pull request](https://github.com/Kaviyes/kaviyesutil/compare) here!\r\n\r\n<br>\r\n<br>\r\n<br>\r\n<br>\r\n\r\n<p align=\"center\">\r\n <a href=\"https://github.com/Kaviyes/\">\r\n <img src=\"https://raw.githubusercontent.com/Kaviyes/kaviyesutil/main/Kaviyes-Text.png\" alt=\"KAVIYES\" width=\"500\"/>\r\n </a>\r\n</p>\r\n\r\n<br>\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A standard kaviyes utility for python thats ideal for small projects and prototypes.",
"version": "2.1.2",
"project_urls": {
"Homepage": "https://github.com/Kaviyes/kaviyesutil"
},
"split_keywords": [
"utility",
" toolkit"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a4660d1c52f05119e0e267e46916bcbb5583d33d10751d36cbc9ac888ec238ce",
"md5": "a9851ebf3ec88b25235cc415c01b59cc",
"sha256": "cee5ddb355c28ab63236998939a69541a602e80359ae7dc9b0622dd6966cdc02"
},
"downloads": -1,
"filename": "kaviyesutil-2.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a9851ebf3ec88b25235cc415c01b59cc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 14707,
"upload_time": "2024-08-24T13:00:17",
"upload_time_iso_8601": "2024-08-24T13:00:17.628817Z",
"url": "https://files.pythonhosted.org/packages/a4/66/0d1c52f05119e0e267e46916bcbb5583d33d10751d36cbc9ac888ec238ce/kaviyesutil-2.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4f103d89182228866d9c971786ae8e8c7b0341a09d41b0de77d063dcd75fc510",
"md5": "0bd65256cc04461b87e7dc0c76973a99",
"sha256": "14029a2855411a4fafde1e3a10d2aa9562cdfaccbd62227f63bbe281b7c5370e"
},
"downloads": -1,
"filename": "kaviyesutil-2.1.2.tar.gz",
"has_sig": false,
"md5_digest": "0bd65256cc04461b87e7dc0c76973a99",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 12875,
"upload_time": "2024-08-24T13:00:19",
"upload_time_iso_8601": "2024-08-24T13:00:19.115174Z",
"url": "https://files.pythonhosted.org/packages/4f/10/3d89182228866d9c971786ae8e8c7b0341a09d41b0de77d063dcd75fc510/kaviyesutil-2.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-24 13:00:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Kaviyes",
"github_project": "kaviyesutil",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "kaviyesutil"
}