File size: 735 Bytes
e26cd2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from functools import lru_cache
from pathlib import Path


@lru_cache
def load_codes_from_files() -> dict:
    with Path("youtube.json").open("r", encoding="utf-8") as file:
        return json.load(file)


def num_prettier(num: int) -> str:
    number = abs(num)
    if number >= (comparer := 1e12):
        prettier_num = f"{number / comparer:.1f}T"
    elif number >= (comparer := 1e9):
        prettier_num = f"{number / comparer:.1f}B"
    elif number >= (comparer := 1e6):
        prettier_num = f"{number / comparer:.1f}M"
    elif number >= (comparer := 1e3):
        prettier_num = f"{number / comparer:.1f}k"
    else:
        prettier_num = str(number)
    return f"-{prettier_num}" if num < 0 else prettier_num