This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| from sys import platform | |
| import mss | |
| from pathlib import Path | |
| def take_screenshot(monitor_number: int = -1, output_file_name: Path = Path(r"screenshot.png")) -> None: | |
| """ | |
| Take a screenshot of a monitor. | |
| Parameters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| from sys import getsizeof | |
| import humanize | |
| # Definition | |
| def print_object_size(object: object) -> None: | |
| """Prints the size of an object in a human-readable format.""" | |
| try: | |
| if hasattr(object, "__sizeof__"): | |
| size_in_bytes: int = getsizeof(object) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| import psutil | |
| import humanize | |
| # Definition | |
| def print_disk_info(only_physical: bool = True) -> None: | |
| """Prints disk partition information.""" | |
| bast_str: str = "Disk Information:" | |
| for partition in psutil.disk_partitions(all=not only_physical): | |
| partition_disk_info = psutil.disk_usage(path=partition.mountpoint) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| import psutil | |
| import humanize | |
| # Definition | |
| def print_ram_info() -> None: | |
| """Prints the available and total RAM information.""" | |
| total_ram, available_ram = psutil.virtual_memory()[:2] | |
| available_ram_str = humanize.naturalsize(available_ram, binary=False) | |
| total_ram_str = humanize.naturalsize(total_ram, binary=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| import psutil | |
| from sys import platform | |
| def print_cpu_info( | |
| print_cpu_count: bool = True, | |
| print_cpu_freq: bool = True, | |
| print_cpu_percent: bool = True, | |
| print_cpu_percent_interval: int = 1, | |
| print_cpu_percent_per_cpu: bool = True, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing libraries | |
| import zipfile | |
| from pathlib import Path | |
| # Specifying the path to the zip file and extraction destination | |
| archive_data_file_path: Path = Path('data/new_archive.zip') | |
| def zip_with_options( | |
| source: Path, | |
| zip_path: Path, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing libraries | |
| from zipfile import ZipFile, BadZipFile | |
| from tarfile import TarFile, TarError | |
| from rarfile import RarFile, BadRarFile | |
| from humanize import naturalsize | |
| from pathlib import Path | |
| from typing import Optional, List, Union, Protocol | |
| from contextlib import contextmanager | |
| from datetime import datetime | |
| import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing the libraries | |
| import sys | |
| # Printing the exact version | |
| python_version : str = sys.version | |
| print(f'The python version is: {python_version}') | |
| # Making sure that the python version meets the requirements | |
| assert sys.version_info >= (3, 11, 9), f'The python version ({python_version}) does not meet the requirements!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing libraries | |
| from packaging import version # This sub-module is used for checking the version of a package | |
| import sklearn as sk # Import the desired package as usual | |
| # Defining some values | |
| package_name : str = sk.__name__ | |
| package_version : str = version.parse(sk.__version__) | |
| package_version_required : str = '1.5.2' # This is an example | |
| # Printing the exact version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from urllib.request import Request, urlopen, urlretrieve | |
| from urllib.parse import urlparse, unquote | |
| from urllib import error | |
| from datetime import datetime | |
| from typing import Dict, Optional | |
| import humanize | |
| def retrieve_file_info(url: str) -> Optional[Dict[str, str]]: |