11import json
2+ import ssl
3+
24import requests
5+ import urllib3
36from bs4 import BeautifulSoup
7+
48from uk_bin_collection .uk_bin_collection .common import *
59from uk_bin_collection .uk_bin_collection .get_bin_data import AbstractGetBinDataClass
6- import ssl
7- import urllib3
810
911
1012class CustomHttpAdapter (requests .adapters .HTTPAdapter ):
@@ -45,7 +47,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
4547 "Sec-Fetch-Dest" : "empty" ,
4648 "Sec-Fetch-Mode" : "cors" ,
4749 "Sec-Fetch-Site" : "same-origin" ,
48- "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116 .0.5845.188 Safari/537.36" ,
50+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134 .0.0.0 Safari/537.36" ,
4951 "X-Requested-With" : "XMLHttpRequest" ,
5052 }
5153
@@ -56,7 +58,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
5658
5759 requests .packages .urllib3 .disable_warnings ()
5860 response = session .get (
59- f"https://www .bathnes.gov.uk/webapi/api/BinsAPI/v2/getbartecroute/ { user_uprn } /true " ,
61+ f"https://api .bathnes.gov.uk/webapi/api/BinsAPI/v2/BartecFeaturesandSchedules/CollectionSummary/ { user_uprn } " ,
6062 headers = headers ,
6163 )
6264 if response .text == "" :
@@ -68,30 +70,14 @@ def parse_data(self, page: str, **kwargs) -> dict:
6870
6971 data = {"bins" : []}
7072
71- if len (json_data ["residualNextDate" ]) > 0 :
72- dict_data = {
73- "type" : "Black Rubbish Bin" ,
74- "collectionDate" : datetime .strptime (
75- json_data ["residualNextDate" ], "%Y-%m-%dT%H:%M:%S"
76- ).strftime (date_format ),
77- }
78- data ["bins" ].append (dict_data )
79- if len (json_data ["recyclingNextDate" ]) > 0 :
80- dict_data = {
81- "type" : "Recycling Containers" ,
82- "collectionDate" : datetime .strptime (
83- json_data ["recyclingNextDate" ], "%Y-%m-%dT%H:%M:%S"
84- ).strftime (date_format ),
85- }
86- data ["bins" ].append (dict_data )
87- if len (json_data ["organicNextDate" ]) > 0 :
88- dict_data = {
89- "type" : "Garden Waste" ,
90- "collectionDate" : datetime .strptime (
91- json_data ["organicNextDate" ], "%Y-%m-%dT%H:%M:%S"
92- ).strftime (date_format ),
93- }
94- data ["bins" ].append (dict_data )
73+ for collection in json_data :
74+ collection_date = datetime .fromisoformat (collection ["nextCollectionDate" ])
75+ for feature in collection ["features" ]:
76+ dict_data = {
77+ "type" : feature ["featureDisplayName" ],
78+ "collectionDate" : collection_date .strftime (date_format ),
79+ }
80+ data ["bins" ].append (dict_data )
9581
9682 data ["bins" ].sort (
9783 key = lambda x : datetime .strptime (x .get ("collectionDate" ), date_format )
0 commit comments