mirror of
https://github.com/NohamR/OqeeAdWatch.git
synced 2026-01-11 00:38:16 +00:00
Lint + update
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
"""Utility functions for the visualizer."""
|
||||
|
||||
from datetime import datetime
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
import sys
|
||||
|
||||
from utils.scrap import fetch_service_plan
|
||||
|
||||
# Allow running as a script from anywhere
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from utils.scrap import fetch_service_plan
|
||||
|
||||
# Load CHANNELS_DATA once when this module is imported
|
||||
CHANNELS_DATA: Dict = fetch_service_plan()
|
||||
|
||||
|
||||
def format_duration(seconds: int) -> str:
|
||||
"""Format a duration in seconds into a human-readable string (e.g., '1h 2m 3s')."""
|
||||
minutes, secs = divmod(seconds, 60)
|
||||
@@ -24,4 +27,16 @@ def format_duration(seconds: int) -> str:
|
||||
|
||||
def human_ts(ts_value: int) -> str:
|
||||
"""Convert a Unix timestamp to a human-readable date and time string."""
|
||||
return datetime.fromtimestamp(ts_value).strftime("%d/%m/%Y at %H:%M:%S")
|
||||
return datetime.fromtimestamp(ts_value).strftime("%d/%m/%Y at %H:%M:%S")
|
||||
|
||||
|
||||
def get_channel_name(channel_id: str, channels_data: Dict = None) -> str:
|
||||
"""Get the channel name from channel_id, or return channel_id if not found."""
|
||||
if channels_data is None:
|
||||
channels_data = CHANNELS_DATA
|
||||
channel_name = channel_id
|
||||
for ch_id, channel_info in channels_data.items():
|
||||
if ch_id == channel_id:
|
||||
channel_name = channel_info["name"]
|
||||
break
|
||||
return channel_name
|
||||
|
||||
Reference in New Issue
Block a user