From 89d74244670f58cff5a236b49aab1f7a94cced60 Mon Sep 17 00:00:00 2001 From: magnus2142 <magnus.bredeli@hotmail.com> Date: Mon, 28 Mar 2022 15:36:59 +0200 Subject: [PATCH] added helper methods for handling cookies, headers and converting html to text --- bbcli/utils/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bbcli/utils/utils.py b/bbcli/utils/utils.py index 1f58f83..be69a2a 100644 --- a/bbcli/utils/utils.py +++ b/bbcli/utils/utils.py @@ -1,4 +1,8 @@ from datetime import datetime +from typing import Dict, List +from requests import Session +import html2text + def check_valid_key(obj, key) -> bool: # print("the keys are", obj.keys()) @@ -31,3 +35,16 @@ def check_valid_date(cookies) -> bool: return False +def set_cookies(session: Session, cookies: List): + for cookie in cookies: + session.cookies.set(cookie['name'], cookie['value']) + + +def set_headers(session: Session, headers: List): + for header in headers: + session.headers.update(header) + + +def html_to_text(html_data: str): + to_text = html2text.HTML2Text() + return to_text.handle(html_data) \ No newline at end of file -- GitLab