From cdc617c382f165fe3171cf1972e3513782b48dc7 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 29 Mar 2022 16:47:21 +0700 Subject: [PATCH] add datestr generator --- tubearchivist/home/src/ta/helper.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tubearchivist/home/src/ta/helper.py b/tubearchivist/home/src/ta/helper.py index 3a1af52..31ba727 100644 --- a/tubearchivist/home/src/ta/helper.py +++ b/tubearchivist/home/src/ta/helper.py @@ -8,6 +8,7 @@ import re import string import subprocess import unicodedata +from datetime import datetime from urllib.parse import parse_qs, urlparse import yt_dlp @@ -88,6 +89,16 @@ def requests_headers(): return {"User-Agent": template} +def date_praser(timestamp): + """return formatted date string""" + if isinstance(timestamp, int): + date_obj = datetime.fromtimestamp(timestamp) + elif isinstance(timestamp, str): + date_obj = datetime.strptime(timestamp, "%Y-%m-%d") + + return datetime.strftime(date_obj, "%d %b, %Y") + + class UrlListParser: """take a multi line string and detect valid youtube ids"""