-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (28 loc) · 1.11 KB
/
utils.py
File metadata and controls
36 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import re
from typing import Tuple, Optional
def parse_movie_title(text: str) -> Tuple[str, Optional[int]]:
"""
Parse movie title and year from text.
Example input: "The Matrix (1999)"
Returns: ("The Matrix", 1999)
"""
# Pattern to match title and optional year in parentheses
pattern = r"(.+?)(?:\s*\((\d{4})\))?$"
match = re.match(pattern, text.strip())
if match:
title = match.group(1).strip()
year = int(match.group(2)) if match.group(2) else None
return title, year
return text.strip(), None
def is_admin(user_id: int, admin_ids: list) -> bool:
"""Check if user is an admin."""
return user_id in admin_ids
def is_authorized_group(group_id: int, auth_groups: list) -> bool:
"""Check if group is authorized."""
return group_id in auth_groups
def format_movie_info(movie) -> str:
"""Format movie information for display."""
year_str = f" ({movie.year})" if movie.year else ""
description = f"\n\n{movie.description}" if movie.description else ""
return f"🎬 *{movie.title}*{year_str}{description}"