Skip to content

Instantly share code, notes, and snippets.

@mdmitry1
Last active November 9, 2025 20:34
Show Gist options
  • Select an option

  • Save mdmitry1/02ac507e2b0ca32cbfd5b59bd808fefd to your computer and use it in GitHub Desktop.

Select an option

Save mdmitry1/02ac507e2b0ca32cbfd5b59bd808fefd to your computer and use it in GitHub Desktop.
Example of using typer
#!/usr/bin/python3.12
import questionary
from questionary import Style
from rich.console import Console
console_256=Console(color_system="256")
fancy = Style([
('qmark', 'fg:#673ab7 bold'),
('question', 'bold'),
('answer', 'fg:#ff00ff bg:#ffffff nobold'),
('pointer', 'fg:#673ab7 bold'),
('highlighted', 'fg:#673ab7 nobold'),
('selected', 'fg:#cc5454'),
('separator', 'fg:#cc5454'),
('instruction', ''),
('text', ''),
('disabled', 'fg:#858585 italic')
])
name = questionary.text("Как назовем проект?", style=fancy).ask()
console_256.print(f"Отлично, создаем проект с именем: [dark_green on white]{name}")
use_git = questionary.confirm("Инициализировать Git-репозиторий?", style=fancy).ask()
if use_git:
console_256.print("[dark_green on white]Хорошо, запускаю git init...")
else:
console_256.print("[dark_green on white]Окей, работаем без git.")
license_type = questionary.select(
"Какую лицензию вы хотите использовать?",
choices=["MIT", "GPLv3", "Apache 2.0", "Без лицензии"],
default="MIT",style=fancy
).ask()
console_256.print(f"Выбрана лицензия: [dark_green on white]{license_type}")
#!/usr/bin/tcsh -f
`realpath $0 | xargs dirname`/site_checker.py \
https://github.com/mdmitry1 \
https://gist.github.com \
https://py-tools.com \
https://this-is-a-fake-domain.net
#!/usr/bin/python3.12
'''
https://habr.com/ru/articles/962608
'''
import typer
import requests
import platform
from typing import List
from rich.console import Console
from rich.table import Table
from rich.progress import track
console = Console()
def is_running_in_wsl():
"""
Checks if the current Python environment is running within WSL.
"""
release_info = platform.release()
return "-Microsoft" in release_info or "microsoft-standard-WSL" in release_info
def get_status_emoji(status_code: int) -> str:
"""Возвращает эмодзи в зависимости от статус-кода."""
ok = ['✅','✅']
redirect = ['➡️','➡️']
client_error = ['❌','❌']
server_error = ['🔥','🔥']
unknown = ['❓','❓']
if 200 <= status_code < 300:
return ok[is_running_in_wsl()] + " OK"
elif 300 <= status_code < 400:
return redirect[is_running_in_wsl()] + " REDIRECT"
elif 400 <= status_code < 500:
return client_error[is_running_in_wsl()] + " CLIENT ERROR"
elif 500 <= status_code < 600:
return server_error[is_running_in_wsl()] + " SERVER ERROR"
return unknown[is_running_in_wsl()] + " UNKNOWN"
def main(urls: List[str] = typer.Argument(..., help="Список URL для проверки.")):
"""
Проверяет доступность сайтов и выводит результат в виде таблицы.
"""
table = Table(title="Результаты проверки сайтов")
table.add_column("URL", style="cyan", no_wrap=True)
table.add_column("Статус код", justify="center")
table.add_column("Статус", justify="left", style="green")
for url in track(urls, description="Проверка сайтов..."):
try:
response = requests.get(url, timeout=5)
status_code = response.status_code
status_text = get_status_emoji(status_code)
# Раскрашиваем строку в зависимости от статуса
row_style = ""
if 300 <= status_code < 400:
row_style = "yellow"
elif status_code >= 400:
row_style = "red"
table.add_row(url, str(status_code), status_text, style=row_style)
except requests.exceptions.RequestException as e:
error_symbol=['💥','💥']
table.add_row(url, "N/A", f"{error_symbol[is_running_in_wsl()]} ERROR: {e.__class__.__name__}", style="bold red")
console.print(table)
if __name__ == "__main__":
typer.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment