Skip to content

Commit 5d34aa5

Browse files
run ruff format
1 parent 0e31b43 commit 5d34aa5

6 files changed

Lines changed: 83 additions & 43 deletions

File tree

utils/msl/activities.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
2121

2222

23-
ACTIVITIES_URL: Final[str] = f"https://www.guildofstudents.com/organisation/admin/activities/all/{ORGANISATION_ID}/"
23+
ACTIVITIES_URL: Final[str] = (
24+
f"https://www.guildofstudents.com/organisation/admin/activities/all/{ORGANISATION_ID}/"
25+
)
2426

2527
ACTIVITIES_BUTTON_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$fsFilter$btnSubmit"
2628
ACTIVITIES_TABLE_ID: Final[str] = "ctl00_ctl00_Main_AdminPageContent_gvResults"
@@ -67,7 +69,10 @@ async def fetch_guild_activities(from_date: "datetime", to_date: "datetime") ->
6769
headers=BASE_HEADERS,
6870
cookies=cookies,
6971
)
70-
async with session_v2, session_v2.post(url=ACTIVITIES_URL, data=data_fields) as http_response: # noqa: E501
72+
async with (
73+
session_v2,
74+
session_v2.post(url=ACTIVITIES_URL, data=data_fields) as http_response,
75+
):
7176
if http_response.status != 200:
7277
logger.debug("Returned a non 200 status code!!")
7378
logger.debug(http_response)
@@ -97,7 +102,9 @@ async def fetch_guild_activities(from_date: "datetime", to_date: "datetime") ->
97102
activities_list.pop(0)
98103

99104
return {
100-
activity.find(name="a").get("href").split("/")[7]: activity.find_all(name="td")[1].text.strip() # type: ignore[union-attr] # noqa: E501
105+
activity.find(name="a").get("href").split("/")[7]: activity.find_all(name="td")[
106+
1
107+
].text.strip() # type: ignore[union-attr]
101108
for activity in activities_list
102109
}
103110

utils/msl/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050

5151
ORGANISATION_ID: Final[str] = settings["ORGANISATION_ID"]
5252

53-
ORGANISATION_ADMIN_URL: Final[str] = f"https://www.guildofstudents.com/organisation/admin/{ORGANISATION_ID}/"
53+
ORGANISATION_ADMIN_URL: Final[str] = (
54+
f"https://www.guildofstudents.com/organisation/admin/{ORGANISATION_ID}/"
55+
)
5456

5557

5658
async def get_msl_context(url: str) -> tuple[dict[str, str], dict[str, str]]:
@@ -60,7 +62,7 @@ async def get_msl_context(url: str) -> tuple[dict[str, str], dict[str, str]]:
6062
cookies=BASE_COOKIES,
6163
)
6264
data_fields: dict[str, str] = {}
63-
cookies: dict[str ,str] = {}
65+
cookies: dict[str, str] = {}
6466
async with http_session, http_session.get(url=url) as field_data:
6567
data_response = BeautifulSoup(
6668
markup=await field_data.text(),

utils/msl/events.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
EVENTS_TO_DATE_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$datesFilter$txtToDate"
2020
EVENTS_BUTTON_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$fsSetDates$btnSubmit"
2121
EVENTS_TABLE_ID: Final[str] = "ctl00_ctl00_Main_AdminPageContent_gvEvents"
22-
CREATE_EVENT_URL: Final[str] = f"https://www.guildofstudents.com/events/edit/event/{ORGANISATION_ID}/"
22+
CREATE_EVENT_URL: Final[str] = (
23+
f"https://www.guildofstudents.com/events/edit/event/{ORGANISATION_ID}/"
24+
)
2325
EVENT_LIST_URL: Final[str] = f"https://www.guildofstudents.com/events/edit/{ORGANISATION_ID}/"
2426

2527

@@ -45,7 +47,10 @@ async def get_all_guild_events(from_date: str, to_date: str) -> dict[str, str]:
4547
headers=BASE_HEADERS,
4648
cookies=cookies,
4749
)
48-
async with session_v2, session_v2.post(url=EVENT_LIST_URL, data=data_fields) as http_response: # noqa: E501
50+
async with (
51+
session_v2,
52+
session_v2.post(url=EVENT_LIST_URL, data=data_fields) as http_response,
53+
):
4954
if http_response.status != 200:
5055
logger.debug("Returned a non 200 status code!!")
5156
logger.debug(http_response)
@@ -54,12 +59,12 @@ async def get_all_guild_events(from_date: str, to_date: str) -> dict[str, str]:
5459
response_html: str = await http_response.text()
5560

5661
event_table_html: bs4.Tag | bs4.NavigableString | None = BeautifulSoup(
57-
markup=response_html,
58-
features="html.parser",
59-
).find(
60-
name="table",
61-
attrs={"id": EVENTS_TABLE_ID},
62-
)
62+
markup=response_html,
63+
features="html.parser",
64+
).find(
65+
name="table",
66+
attrs={"id": EVENTS_TABLE_ID},
67+
)
6368

6469
if event_table_html is None or isinstance(event_table_html, bs4.NavigableString):
6570
logger.debug("Something went wrong!")

utils/msl/finances.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
__all__: "Sequence[str]" = ()
2323

24-
FINANCE_REDIRECT_URL: Final[str] = f"https://www.guildofstudents.com/sgf/{ORGANISATION_ID}/Landing/Member"
24+
FINANCE_REDIRECT_URL: Final[str] = (
25+
f"https://www.guildofstudents.com/sgf/{ORGANISATION_ID}/Landing/Member"
26+
)
2527
FINANCES_URL: Final[str] = f"https://guildofstudents.com/sgf/{ORGANISATION_ID}/Home/Dashboard/"
26-
BASE_EXPENSE_URL: Final[str] = f"https://guildofstudents.com/sgf/{ORGANISATION_ID}/Request/Edit?RequestId="
28+
BASE_EXPENSE_URL: Final[str] = (
29+
f"https://guildofstudents.com/sgf/{ORGANISATION_ID}/Request/Edit?RequestId="
30+
)
2731

2832

2933
logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
@@ -63,8 +67,9 @@ async def get_available_balance() -> float | None:
6367
headers=BASE_HEADERS,
6468
cookies=BASE_COOKIES,
6569
)
66-
async with cookie_session, cookie_session.get(url=ORGANISATION_ADMIN_URL) as (
67-
cookie_response
70+
async with (
71+
cookie_session,
72+
cookie_session.get(url=ORGANISATION_ADMIN_URL) as (cookie_response),
6873
):
6974
if cookie_response.status != 200:
7075
logger.debug("Returned a non 200 status code!!")
@@ -110,7 +115,10 @@ async def get_available_balance() -> float | None:
110115

111116
return None
112117

113-
async def fetch_financial_transactions(limit: int | None = None, transaction_type: TransactionType | None = None) -> dict[str, str]: # noqa: E501
118+
119+
async def fetch_financial_transactions(
120+
limit: int | None = None, transaction_type: TransactionType | None = None
121+
) -> dict[str, str]:
114122
"""
115123
Return the most recent `limit` transactions.
116124

utils/msl/memberships.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
from collections.abc import Sequence
1414
from logging import Logger
1515

16-
__all__: "Sequence[str]" = ("get_full_membership_list", "get_membership_count", "is_student_id_member")
16+
__all__: "Sequence[str]" = (
17+
"get_full_membership_list",
18+
"get_membership_count",
19+
"is_student_id_member",
20+
)
1721

18-
MEMBERS_LIST_URL: Final[str] = f"https://guildofstudents.com/organisation/memberlist/{ORGANISATION_ID}/?sort=groups"
22+
MEMBERS_LIST_URL: Final[str] = (
23+
f"https://guildofstudents.com/organisation/memberlist/{ORGANISATION_ID}/?sort=groups"
24+
)
1925

2026
persistent_membership_list: set[tuple[str, int]] = set()
2127

@@ -52,9 +58,8 @@ async def get_full_membership_list() -> set[tuple[str, int]]:
5258
logger.debug(response_html)
5359
return set()
5460

55-
if (
56-
isinstance(standard_members_table, bs4.NavigableString) or
57-
isinstance(all_members_table, bs4.NavigableString)
61+
if isinstance(standard_members_table, bs4.NavigableString) or isinstance(
62+
all_members_table, bs4.NavigableString
5863
):
5964
logger.warning(
6065
"Both membership tables were found but one or both are the wrong format!",
@@ -69,9 +74,12 @@ async def get_full_membership_list() -> set[tuple[str, int]]:
6974
standard_members.pop(0)
7075
all_members.pop(0)
7176

72-
member_list: set[tuple[str, int]] = {(
73-
member.find_all(name="td")[0].text.strip(),
74-
member.find_all(name="td")[1].text.strip(), # NOTE: This will not properly handle external members who do not have an ID... There does not appear to be a solution to this other than simply checking manually.
77+
member_list: set[tuple[str, int]] = {
78+
(
79+
member.find_all(name="td")[0].text.strip(),
80+
member.find_all(name="td")[
81+
1
82+
].text.strip(), # NOTE: This will not properly handle external members who do not have an ID... There does not appear to be a solution to this other than simply checking manually.
7583
)
7684
for member in standard_members + all_members
7785
}
@@ -84,9 +92,7 @@ async def get_full_membership_list() -> set[tuple[str, int]]:
8492

8593
async def is_student_id_member(student_id: str | int) -> bool:
8694
"""Check if the student ID is a member of the society."""
87-
all_ids: set[str] = {
88-
str(member[1]) for member in persistent_membership_list
89-
}
95+
all_ids: set[str] = {str(member[1]) for member in persistent_membership_list}
9096

9197
if str(student_id) in all_ids:
9298
return True

utils/msl/reports.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
logger: "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+
)
3436
SALES_FROM_DATE_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtFromDate"
3537
SALES_FROM_TIME_KEY: Final[str] = "ctl00$ctl00$Main$AdminPageContent$drDateRange$txtFromTime"
3638
SALES_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

Comments
 (0)