Skip to content

Instantly share code, notes, and snippets.

View dvonpasecky's full-sized avatar

Dan Von Pasecky dvonpasecky

View GitHub Profile
@dvonpasecky
dvonpasecky / section.py
Created February 19, 2024 05:31
section
import logging
from functools import wraps
from typing import Any, Callable
logger = logging.getLogger(__name__)
def section(section_name: str, sep_char: str = "=", sep_len: int = 88) -> Callable:
"""Decorator to log a section name at the start and end of a function's execution.
@dvonpasecky
dvonpasecky / async_requests.py
Created February 19, 2024 04:52
async_requests
import asyncio
from typing import List
import aiohttp
async def fetch(url: str, session: aiohttp.ClientSession) -> str:
"""Asynchronously fetches the content from a URL using aiohttp.
Args:
@dvonpasecky
dvonpasecky / configurator.py
Last active March 19, 2024 00:34
configurator
import json
import logging
import logging.config
from datetime import datetime
from pathlib import Path
from typing import Callable, Dict
import tomllib
import yaml
@dvonpasecky
dvonpasecky / setup_logging.py
Created July 21, 2023 01:07
setup_logging.py
def setup_logging(
config_filename: PathLike = "logging.yaml", log_dir: PathLike = "logs"
) -> logging.Logger:
"""Get logger object."""
log_path = Path(log_dir)
log_path.mkdir(exist_ok=True, parents=True)
config = load_config(config_filename)
config["handlers"]["file"]["filename"] = (
@dvonpasecky
dvonpasecky / filelock.py
Last active April 30, 2023 07:33
filelock.py
import logging
from functools import wraps
from pathlib import Path
from typing import Union
logger = logging.getLogger(__name__)
class FileLock:
"""