uk_bin_collection 0.122.0__py3-none-any.whl → 0.123.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -134,6 +134,32 @@ def test_is_holiday_different_region(mock_holidays_func):
134
134
  assert is_holiday(datetime(2023, 11, 30), Region.ENG) is False
135
135
 
136
136
 
137
+ def test_is_weekend_when_true():
138
+ weekend_date = datetime(2024, 12, 7)
139
+ assert is_weekend(weekend_date) is True
140
+
141
+
142
+ def test_is_weekend_when_false():
143
+ weekend_date = datetime(2024, 12, 6)
144
+ assert is_weekend(weekend_date) is False
145
+
146
+
147
+ def test_is_working_day_when_true():
148
+ working_day_date = datetime(2024, 12, 6)
149
+ assert is_working_day(working_day_date) is True
150
+
151
+
152
+ def test_is_working_day_when_false():
153
+ working_day_date = datetime(2024, 12, 7)
154
+ assert is_working_day(working_day_date) is False
155
+
156
+
157
+ def test_get_next_working_day():
158
+ sample_date = datetime(2024, 12, 7)
159
+ next_working_day = get_next_working_day(sample_date)
160
+ assert next_working_day == datetime(2024, 12, 9)
161
+
162
+
137
163
  def test_remove_alpha_characters():
138
164
  test_string = "12345abc12345"
139
165
  result = remove_alpha_characters(test_string)
@@ -10,7 +10,6 @@ import pandas as pd
10
10
  import requests
11
11
  from dateutil.parser import parse
12
12
  from selenium import webdriver
13
- from selenium.common.exceptions import WebDriverException
14
13
  from selenium.webdriver.chrome.service import Service as ChromeService
15
14
  from urllib3.exceptions import MaxRetryError
16
15
  from webdriver_manager.chrome import ChromeDriverManager
@@ -162,6 +161,31 @@ def is_holiday(date_to_check: datetime, region: Region = Region.ENG) -> bool:
162
161
  return False
163
162
 
164
163
 
164
+ def is_weekend(date_to_check: datetime) -> bool:
165
+ """
166
+ Checks if a given date is a weekend
167
+ :param date_to_check: Date to check if it falls on a weekend
168
+ :return: Bool - true if a weekend day, false if not
169
+ """
170
+ return True if date_to_check.date().weekday() >= 5 else False
171
+
172
+
173
+ def is_working_day(date_to_check: datetime, region: Region = Region.ENG) -> bool:
174
+ """
175
+ Wraps is_holiday() and is_weekend() into one function
176
+ :param date_to_check: Date to check if holiday
177
+ :param region: The UK nation to check. Defaults to ENG.
178
+ :return: Bool - true if a working day (non-holiday, Mon-Fri).
179
+ """
180
+ return False if is_holiday(date_to_check, region) or is_weekend(date_to_check) else True
181
+
182
+
183
+ def get_next_working_day(date: datetime, region: Region = Region.ENG) -> datetime:
184
+ while not is_working_day(date, region):
185
+ date += timedelta(days=1)
186
+ return date
187
+
188
+
165
189
  def get_weekday_dates_in_period(start: datetime, day_of_week: int, amount=8) -> list:
166
190
  """
167
191
  Returns a list of dates of a given weekday from a start date for the given amount of weeks
@@ -208,7 +232,7 @@ def get_next_occurrence_from_day_month(date: datetime) -> datetime:
208
232
 
209
233
  # Check if the target date has already occurred this year
210
234
  if (target_month < current_month) or (
211
- target_month == current_month and target_day < current_day
235
+ target_month == current_month and target_day < current_day
212
236
  ):
213
237
  date = pd.to_datetime(date) + pd.DateOffset(years=1)
214
238
 
@@ -291,10 +315,10 @@ def contains_date(string, fuzzy=False) -> bool:
291
315
 
292
316
 
293
317
  def create_webdriver(
294
- web_driver: str = None,
295
- headless: bool = True,
296
- user_agent: str = None,
297
- session_name: str = None,
318
+ web_driver: str = None,
319
+ headless: bool = True,
320
+ user_agent: str = None,
321
+ session_name: str = None,
298
322
  ) -> webdriver.Chrome:
299
323
  """
300
324
  Create and return a Chrome WebDriver configured for optional headless operation.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.122.0
3
+ Version: 0.123.0
4
4
  Summary: Python Lib to collect UK Bin Data
5
5
  Author: Robert Bradley
6
6
  Author-email: robbrad182@gmail.com
@@ -7,11 +7,11 @@ uk_bin_collection/tests/output.schema,sha256=ZwKQBwYyTDEM4G2hJwfLUVM-5v1vKRvRK9W
7
7
  uk_bin_collection/tests/step_defs/step_helpers/file_handler.py,sha256=Ygzi4V0S1MIHqbdstUlIqtRIwnynvhu4UtpweJ6-5N8,1474
8
8
  uk_bin_collection/tests/step_defs/test_validate_council.py,sha256=VZ0a81sioJULD7syAYHjvK_-nT_Rd36tUyzPetSA0gk,3475
9
9
  uk_bin_collection/tests/test_collect_data.py,sha256=zmj15cb3BWc_ehPqkfzBSa6GZr0txvWumgbAk3Lyyf0,2252
10
- uk_bin_collection/tests/test_common_functions.py,sha256=xvG9_ZihGSwHHAqfXZ6aKSEnoQXhjef7evhcPkBlHeI,14099
10
+ uk_bin_collection/tests/test_common_functions.py,sha256=cCUwXKGijmsvTLz0KoaedXkpos76vc4569yhSvympSI,14800
11
11
  uk_bin_collection/tests/test_conftest.py,sha256=qI_zgGjNOnwE9gmZUiuirL1SYz3TFw5yfGFgT4T3aG4,1100
12
12
  uk_bin_collection/tests/test_get_data.py,sha256=sFJz_Fd6o-1r2gdmzY52JGwVi0Of_mDzvYSoc7a3RUw,7239
13
13
  uk_bin_collection/uk_bin_collection/collect_data.py,sha256=dB7wWXsJX4fm5bIf84lexkvHIcO54CZ3JPxqmS-60YY,4654
14
- uk_bin_collection/uk_bin_collection/common.py,sha256=fJG9ruqsCYOaYm-fzRb_l5kTeeB7i9k7qphWt3t7kks,10107
14
+ uk_bin_collection/uk_bin_collection/common.py,sha256=Wj6o2NaxYDE1lkpYzMFDIZiPARX0K3xmt-5bnt2kjSI,10970
15
15
  uk_bin_collection/uk_bin_collection/councils/AberdeenCityCouncil.py,sha256=Je8VwVLK9KnYl9vqf2gWJ7ZYDgUq3A7caDiIzk5Xof8,4194
16
16
  uk_bin_collection/uk_bin_collection/councils/AberdeenshireCouncil.py,sha256=aO1CSdyqa8oAD0fB79y1Q9bikAWCP_JFa7CsyTa2j9s,1655
17
17
  uk_bin_collection/uk_bin_collection/councils/AdurAndWorthingCouncils.py,sha256=ppbrmm-MzB1wOulK--CU_0j4P-djNf3ozMhHnmQFqLo,1511
@@ -287,8 +287,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
287
287
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=EQWRhZ2pEejlvm0fPyOTsOHKvUZmPnxEYO_OWRGKTjs,1158
288
288
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
289
289
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
290
- uk_bin_collection-0.122.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
291
- uk_bin_collection-0.122.0.dist-info/METADATA,sha256=cuaZZvJNMw784bFqOHyuc7nJOJGOYROQ5LdyS6On0pA,17574
292
- uk_bin_collection-0.122.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
293
- uk_bin_collection-0.122.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
294
- uk_bin_collection-0.122.0.dist-info/RECORD,,
290
+ uk_bin_collection-0.123.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
291
+ uk_bin_collection-0.123.0.dist-info/METADATA,sha256=t9sgA7rjtEYsVf5kuTc-T8f8oF9e9lciaFLzGtjS9BM,17574
292
+ uk_bin_collection-0.123.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
293
+ uk_bin_collection-0.123.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
294
+ uk_bin_collection-0.123.0.dist-info/RECORD,,