3030logger : "Final[Logger]" = logging .getLogger ("TeX-Bot" )
3131
3232
33- SALES_REPORTS_URL : Final [str ] = f"https://www.guildofstudents.com/organisation/salesreports/{ ORGANISATION_ID } /"
33+ SALES_REPORTS_URL : Final [str ] = (
34+ f"https://www.guildofstudents.com/organisation/salesreports/{ ORGANISATION_ID } /"
35+ )
3436SALES_FROM_DATE_KEY : Final [str ] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtFromDate"
3537SALES_FROM_TIME_KEY : Final [str ] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtFromTime"
3638SALES_TO_DATE_KEY : Final [str ] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtToDate"
@@ -52,7 +54,9 @@ class ReportType(Enum):
5254 CUSTOMISATION = "Customisations"
5355
5456
55- async def fetch_report_url_and_cookies (report_type : ReportType , * , from_date : datetime , to_date : datetime ) -> tuple [str | None , dict [str , str ]]: # noqa: E501
57+ async def fetch_report_url_and_cookies (
58+ report_type : ReportType , * , from_date : datetime , to_date : datetime
59+ ) -> tuple [str | None , dict [str , str ]]:
5660 """Fetch the specified report from the guild website."""
5761 data_fields , cookies = await get_msl_context (url = SALES_REPORTS_URL )
5862
@@ -74,7 +78,10 @@ async def fetch_report_url_and_cookies(report_type: ReportType, *, from_date: da
7478 headers = BASE_HEADERS ,
7579 cookies = cookies ,
7680 )
77- async with session_v2 , session_v2 .post (url = SALES_REPORTS_URL , data = data_fields ) as http_response : # noqa: E501
81+ async with (
82+ session_v2 ,
83+ session_v2 .post (url = SALES_REPORTS_URL , data = data_fields ) as http_response ,
84+ ):
7885 if http_response .status != 200 :
7986 logger .debug ("Returned a non 200 status code!!" )
8087 logger .debug (http_response )
@@ -135,10 +142,9 @@ async def update_current_year_sales_report() -> None:
135142 values : list [bytes ] = line .split (b"," )
136143
137144 product_name_and_id : bytes = values [0 ]
138- product_id : bytes = ((
139- product_name_and_id .split (b" " )[0 ].removeprefix (b"[" )
140- ).removesuffix (b"]" )
141- )
145+ product_id : bytes = (
146+ product_name_and_id .split (b" " )[0 ].removeprefix (b"[" )
147+ ).removesuffix (b"]" )
142148 product_name : bytes = b" " .join (
143149 product_name_and_id .split (b" " )[1 :],
144150 )
@@ -148,12 +154,18 @@ async def update_current_year_sales_report() -> None:
148154 total : bytes = values [8 ]
149155
150156 await report_file .write (
151- product_id + b"," +
152- product_name + b"," +
153- date + b"," +
154- quantity + b"," +
155- unit_price + b"," +
156- total + b"\n " ,
157+ product_id
158+ + b","
159+ + product_name
160+ + b","
161+ + date
162+ + b","
163+ + quantity
164+ + b","
165+ + unit_price
166+ + b","
167+ + total
168+ + b"\n " ,
157169 )
158170
159171 logger .debug ("Sales report updated successfully!!" )
@@ -178,7 +190,7 @@ async def get_product_customisations(product_id: str) -> set[dict[str, str]]:
178190 report_url , cookies = await fetch_report_url_and_cookies (
179191 report_type = ReportType .CUSTOMISATION ,
180192 to_date = datetime .now (tz = timezone .utc ), # noqa: UP017
181- from_date = datetime .now (tz = timezone .utc )- timedelta (weeks = 52 ), # noqa: UP017
193+ from_date = datetime .now (tz = timezone .utc ) - timedelta (weeks = 52 ), # noqa: UP017
182194 )
183195
184196 if report_url is None :
0 commit comments