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 inspect, builtins | |
def show_tree(base, level=0, max_depth=1): | |
if level > max_depth: | |
return | |
for name, obj in vars(builtins).items(): | |
if inspect.isclass(obj) and issubclass(obj, base) and obj is not base: | |
print("\t" * level + f"- {name}") | |
show_tree(obj, level + 1, max_depth) |
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 random | |
def retry(max_attempts=3): | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
for attempt in range(1, max_attempts + 1): | |
try: | |
print(f"Attempt {attempt}/{max_attempts}") | |
return func(*args, **kwargs) | |
except Exception as e: |
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
# 1. Ingest the log lines | |
# 2. Filter log lines based on either lever or message substring | |
# 3. Extract and return only the message attribute of the logs | |
import sys | |
import json | |
def read_logs(filepath): | |
"""Reads the contents of a file line by line. |