# Path: common_utils.py
# def fetch_html_page(page_url):
#     user_agent = (
#         "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) "
#         "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36"
#     )
#     headers = {"User-Agent": user_agent}
#     page = requests.get(page_url, headers=headers, timeout=10)
#     return page.text
# 
# def html_parser_from(page_html):
#     return BeautifulSoup(page_html, "html.parser")
# 
# def retry(exceptions, tries=4, delay=3, back_off=2):
#     def deco_retry(f):
#         @wraps(f)
#         def f_retry(*args, **kwargs):
#             m_retries, m_delay = tries, delay
#             while m_retries > 1:
#                 try:
#                     return f(*args, **kwargs)
#                 except exceptions as e:
#                     msg = f"{e}, Retrying in {m_delay} seconds..."
#                     logging.warning(msg)
#                     time.sleep(m_delay)
#                     m_retries -= 1
#                     m_delay *= back_off
#             return f(*args, **kwargs)
# 
#         return f_retry  # true decorator
# 
#     return deco_retry


import argparse
import logging
import os
import py_executable_checklist.workflow
import telegram
from pathlib import Path
from dotenv import load_dotenv
from slug import slug
from telegram import Update
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
from common_utils import fetch_html_page, html_parser_from, retry
#!/usr/bin/env python3
"""
Telegram bot to convert web page links to PDF
"""



load_dotenv()

OUTPUT_DIR = Path.home().joinpath("OutputDir", "web-to-pdf")


def welcome(update: Update, _):
    if update.message:
        update.message.reply_text(
            "👋 Hi there. ⬇️ I'm a bot that converts web pages to PDFs. ⬆️. " "Try sending me a link to a web page"
        )


def help_command(update: Update, _):
    if update.message:
        update.message.reply_text("Help!")


def _handle_web_page(web_page_url: str) -> str:

# Path: common_utils.py
# def fetch_html_page(page_url):
#     user_agent = (
#         "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) "
#         "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36"
#     )
#     headers = {"User-Agent": user_agent}
#     page = requests.get(page_url, headers=headers, timeout=10)
#     return page.text
# 
# def html_parser_from(page_html):
#     return BeautifulSoup(page_html, "html.parser")
# 
# def retry(exceptions, tries=4, delay=3, back_off=2):
#     def deco_retry(f):
#         @wraps(f)
#         def f_retry(*args, **kwargs):
#             m_retries, m_delay = tries, delay
#             while m_retries > 1:
#                 try:
#                     return f(*args, **kwargs)
#                 except exceptions as e:
#                     msg = f"{e}, Retrying in {m_delay} seconds..."
#                     logging.warning(msg)
#                     time.sleep(m_delay)
#                     m_retries -= 1
#                     m_delay *= back_off
#             return f(*args, **kwargs)
# 
#         return f_retry  # true decorator
# 
#     return deco_retry


# Path: rider_brain_bot.py
import argparse
import logging
import os
import py_executable_checklist.workflow
import telegram
from pathlib import Path
from dotenv import load_dotenv
from slug import slug
from telegram import Update
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
from common_utils import fetch_html_page, html_parser_from, retry

#!/usr/bin/env python3
"""
Telegram bot to convert web page links to PDF
"""



load_dotenv()

OUTPUT_DIR = Path.home().joinpath("OutputDir", "web-to-pdf")


def welcome(update: Update, _):
    if update.message:
        update.message.reply_text(
            "👋 Hi there. ⬇️ I'm a bot that converts web pages to PDFs. ⬆️. " "Try sending me a link to a web page"
        )


def help_command(update: Update, _):
    if update.message:
        update.message.reply_text("Help!")


def _handle_web_page(web_page_url: str) -> str:

    page_html = fetch_html_page(web_page_url)