Skip to content

Commit

Permalink
Merge pull request #412 from robbrad/378_fix_northamptonshire_council
Browse files Browse the repository at this point in the history
378 fix northamptonshire council
  • Loading branch information
OliverCullimore authored Nov 1, 2023
2 parents 9407966 + 58fdf9b commit 0ea4e79
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Feature: Test each council output matches expected results in /outputs
| EastDevonDC |
| EastleighBoroughCouncil |
| EastLindseyDistrictCouncil |
| EastNorthamptonshireCouncil |
| EastRidingCouncil |
| EastSuffolkCouncil |
| ErewashBoroughCouncil |
Expand Down Expand Up @@ -67,6 +66,7 @@ Feature: Test each council output matches expected results in /outputs
| NorthLanarkshireCouncil |
| NorthLincolnshireCouncil |
| NorthNorfolkDistrictCouncil |
| NorthNorthamptonshireCouncil |
| NorthSomersetCouncil |
| NorthTynesideCouncil |
| NorthumberlandCouncil |
Expand Down
6 changes: 3 additions & 3 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@
"wiki_name": "East Lindsey District Council",
"wiki_note": "Pass the house name/number in the house number parameter, wrapped in double quotes"
},
"EastNorthamptonshireCouncil": {
"NorthNorthamptonshireCouncil": {
"SKIP_GET_URL": "SKIP_GET_URL",
"uprn": "100031021317",
"url": "https://kbccollectiveapi-coll-api.e4ff.pro-eu-west-1.openshiftapps.com/wc-info/",
"wiki_name": "East Northamptonshire Council"
"url": "https://cms.northnorthants.gov.uk/bin-collection-search/calendarevents/100031021318/2023-10-17/2023-10-01",
"wiki_name": "North Northamptonshire Council"
},
"EastRidingCouncil": {
"SKIP_GET_URL": "SKIP_GET_URL",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import hashlib
import math
import time
from datetime import datetime as dtm, timedelta

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import \
AbstractGetBinDataClass


def myFunc(e):
return e['start']

class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
base class. They can also override some operations with a default
implementation.
"""

def parse_data(self, page: str, **kwargs) -> dict:
data = {"bins": []}
uprn = kwargs.get("uprn")
check_uprn(uprn)
today = int(datetime.now().timestamp())*1000
dateforurl = datetime.now().strftime("%Y-%m-%d")
dateforurl2 = (datetime.now() + timedelta(days=42)).strftime("%Y-%m-%d")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
}
requests.packages.urllib3.disable_warnings()

# Get variables for workings
response = requests.get(
f"https://cms.northnorthants.gov.uk/bin-collection-search/calendarevents/{uprn}/{dateforurl}/{dateforurl2}",
headers=headers,
)
if response.status_code != 200:
raise ValueError("No bin data found for provided UPRN..")

json_response = json.loads(response.text)

output_dict = [x for x in json_response if int(''.join(filter(str.isdigit, x['start']))) >= today]

output_json = output_dict
output_json.sort(key=myFunc)

i = 0
while i < len(output_json):
sov = output_json[i]['title'].lower()
if 'recycling' in sov:
bin_type = "Recycling"
elif 'garden' in sov:
bin_type = "Garden"
elif 'refuse' in sov:
bin_type = "General"
else:
bin_type = "Unknown"
dateofbin = int(''.join(filter(str.isdigit, output_json[i]['start'])))
day = dtm.fromtimestamp(dateofbin/1000)
collection_data = {
"type": bin_type,
"collectionDate": day.strftime(date_format),
}
data["bins"].append(collection_data)
i += 1

return data

0 comments on commit 0ea4e79

Please sign in to comment.