Skip to content

Commit e4f402f

Browse files
Requirements and fixes
1 parent 9406010 commit e4f402f

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

css-reports/report.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""Python script to fetch a customisation report from the Guild website."""
22

33
from typing import Final, Mapping, TYPE_CHECKING
4+
45
import aiohttp
56
import bs4
6-
from bs4 import BeautifulSoup
7+
import certifi
8+
import ssl
79
import re
10+
11+
from bs4 import BeautifulSoup
812
from datetime import datetime
913

1014
if TYPE_CHECKING:
@@ -22,20 +26,26 @@
2226
SALES_TO_TIME_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtToTime"
2327

2428

25-
async def get_msl_context(url: str, auth_cookie: str) -> tuple[dict[str, str], dict[str, str]]:
29+
ssl_context: ssl.SSLContext = ssl.create_default_context(cafile=certifi.where())
30+
31+
32+
async def get_msl_context(
33+
url: str, auth_cookie: str
34+
) -> tuple[dict[str, str], dict[str, str]]:
2635
"""Get the required context headers, data and cookies to make a request to MSL."""
2736

2837
BASE_COOKIES: Mapping[str, str] = {
2938
".ASPXAUTH": auth_cookie,
3039
}
3140

32-
http_session: aiohttp.ClientSession = aiohttp.ClientSession(
33-
headers=BASE_HEADERS,
34-
cookies=BASE_COOKIES,
35-
)
3641
data_fields: dict[str, str] = {}
3742
cookies: dict[str, str] = {}
38-
async with http_session, http_session.get(url=url) as field_data:
43+
async with (
44+
aiohttp.ClientSession(
45+
headers=BASE_HEADERS, cookies=BASE_COOKIES
46+
) as http_session,
47+
http_session.get(url=url, ssl=ssl_context) as field_data,
48+
):
3949
data_response = BeautifulSoup(
4050
markup=await field_data.text(),
4151
features="html.parser",
@@ -87,11 +97,12 @@ async def fetch_report_url_and_cookies(
8797

8898
data_fields.update(form_data)
8999

90-
session_v2: aiohttp.ClientSession = aiohttp.ClientSession(
91-
headers=BASE_HEADERS,
92-
cookies=cookies,
93-
)
94-
async with (session_v2, session_v2.post(url=SALES_REPORTS_URL, data=data_fields) as http_response): # noqa: E501
100+
async with (
101+
aiohttp.ClientSession(headers=BASE_HEADERS, cookies=cookies) as session_v2,
102+
session_v2.post(
103+
url=SALES_REPORTS_URL, data=data_fields, ssl=ssl_context
104+
) as http_response,
105+
): # noqa: E501
95106
if http_response.status != 200:
96107
print("Returned a non 200 status code!!")
97108
print(http_response)
@@ -148,11 +159,10 @@ async def get_product_customisations(
148159
print("Failed to retrieve customisations report URL.")
149160
raise ValueError("Failed to retrieve customisations report URL.")
150161

151-
file_session: aiohttp.ClientSession = aiohttp.ClientSession(
152-
headers=BASE_HEADERS,
153-
cookies=cookies,
154-
)
155-
async with file_session, file_session.get(url=report_url) as file_response:
162+
async with (
163+
aiohttp.ClientSession(headers=BASE_HEADERS, cookies=cookies) as file_session,
164+
file_session.get(url=report_url, ssl=ssl_context) as file_response,
165+
):
156166
if file_response.status != 200:
157167
print("Customisation report file session returned a non 200 status code.")
158168
print(file_response)

css-reports/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Flask[async]
33
aiohttp
44
beautifulsoup4
55
python-dotenv
6-
waitress
6+
waitress
7+
certifi

0 commit comments

Comments
 (0)