Code Monkey home page Code Monkey logo

ukbincollectiondata's Introduction

Hi there ๐Ÿ‘‹

ukbincollectiondata's People

Contributors

actions-user avatar alexforrow avatar andrewpwade avatar anthonyangel avatar bfayers avatar danielcecil avatar dannya avatar dependabot[bot] avatar dp247 avatar github-actions[bot] avatar half-shot avatar imascarenhas avatar jallerton00 avatar jimmygulp avatar markgdev avatar mrw298 avatar mystifiedmeat avatar olivercullimore avatar phildb-cloud avatar philharle avatar richkershaw avatar robbrad avatar ryck avatar sammort avatar seanjcuk avatar simondrake avatar skelt0 avatar thedevfreak avatar zackaryh8 avatar zoenolan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ukbincollectiondata's Issues

Add an issue template

Add issue templates to help better manage the adding of councils, I have provided below an example

Example

image

Code

name: Council Request
description: Request for a council to be added to the repository
labels: ['Class: enhancement']

body:
    - type: input
      id: council
      attributes:
          label: Name of Council
          description: What council are you wishing to be added
          placeholder: e.g. Huntingdon District Council
      validations:
          required: true
    - type: input
      id: postcode
      attributes:
          label: Example Postcode
          description: Please provide and example postcode for the area
          placeholder: e.g. PE7 3YQ
      validations:
          required: true
    - type: textarea
      id: extra
      attributes:
          label: Additional Information
          description: Add any other information here
          placeholder: Links to the councils site, information you have already gathered

Huntingdon District Council

I have linked below my postman collections. This will need to use soup as far as I can see there is no API

Postcode - PE73GD
UPRN     - 10012048674

Run in Postman

Crawley Borough Council

Interesting one, doesn't look like they have an API they require a log in to view your details or at least I thought
https://my.crawley.gov.uk/
looking at the page source you don't have to be logged in once you have a customer info via the page source, I tested this in an incognito window so it should be able to be scraped if someone with the knowhow wants to work with me to get this one working, I just don't want to publicly post my customer info

Charnwood Borough Council

Hi, I have a working script for Charnwood Borough Council and would like to raise a PR to get this into the repo, however I have no access to create a branch. Could you look at the access policies?

Thanks

Release as a Python package

As an end user I would like to consume the repo as a pip package potentially integrated with Home Assistant

Broadland / South Norfolk Council

Name of Council

Broadland & South Norfolk District Council

Example Postcode

NR18 0HA

Additional Information

https://www.southnorfolkandbroadland.gov.uk/rubbish-recycling/south-norfolk-bin-collection-day-finder

Seems like the page provides an iframe to render the results... recording the network requests once you have selected the address, it sends a post request to the following endpoint:

https://collections-southnorfolk.azurewebsites.net/WebService2.asmx
Content-Type must be set to text/xml; charset=UTF-8 text/xml; charset=UTF-8 for it to work

Post body is XML:

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <getRoundCalendarForUPRN xmlns="http://tempuri2.org/">
            <council>SNO</council>
            <UPRN><redacted for privacy></UPRN>
            <PW>wax01653</PW>
        </getRoundCalendarForUPRN>
    </soap:Body>
</soap:Envelope>

I have a feeling changing "SNO" in the above to the shortcode for broadland district council (not sure what it is however) will allow the use of the same endpoint for both (both councils have formed a partnership and somewhat merged recently)

I'm not sure what that PW element is for in the post body, changing it gave me the following response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <getRoundCalendarForUPRNResponse xmlns="http://tempuri2.org/">
            <getRoundCalendarForUPRNResult>UnableToPRocess--Code-IVUsPsRl</getRoundCalendarForUPRNResult>
        </getRoundCalendarForUPRNResponse>
    </soap:Body>
</soap:Envelope>

Sample response on pastebin:

https://pastebin.com/CC6u1FS5

Buckinghamshire Council

name: Council Request
description: Request for a council to be added to the repository
labels: ['Class: enhancement']

body:
- type: input
id: council
attributes:
label: Buckinghamshire
description: Buckinghamshire - Chiltern Area
placeholder: e.g. Huntingdon District Council
validations:
required: true
- type: input
id: postcode
attributes:
label: Example Postcode
description: Please provide and example postcode for the area
placeholder: e.g. HP14 3NL
validations:
required: true
- type: textarea
id: extra
attributes:
label: Additional Information
description: The actual site is a Chiltern.gov site which is a child of the main Buckinghamshire site.
placeholder: (https://www.chiltern.gov.uk/collection-dates) - It seems to take a form submission with a session ID, which is redirected and provides results back in an HTML format. The table at the bottom of the returned page lists the next collection date for each bin type. Thank you!
Capture

Castle Point District Council

Name of Council

Castle Point District Council

Example Postcode

SS8 8AB

Additional Information

This is how far I have got at my first attempt at Python. The council site is https://apps.castlepoint.gov.uk/cpapps/index.cfm?fa=wastecalendar&a=1 and they use a 4 digit road code that I obtained through the url once I had selected my road. My road being Korndyke Avenue = 2757

I did adapt the code to work with Pyscript, that was fine until July's HA update and I'm now getting SSL errors with the URL.

Not sure how this could be adapted into your code if at all but thought I'd post it here incase its of any help.

import datetime
import requests
import calendar
from bs4 import BeautifulSoup


def ord(n):  # returns st, nd, rd and th
    return str(n) + (
        "th" if 4 <= n % 100 <= 20 else {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
    )


def todays_day():
    print(f"Today {(ord(todays_date.day))}")
    if todays_date.day in pink_sack:
        print("is pink")
    elif todays_date.day in black_sack:
        print("is black")


URL = "https://apps.castlepoint.gov.uk/cpapps/index.cfm?roadID=2757&fa=wastecalendar.displayDetails"
raw_html = requests.get(URL)
data = BeautifulSoup(raw_html.text, "lxml")


pink = data.find_all("td", class_="pink", limit=4)
black = data.find_all("td", class_="normal", limit=4)
month = data.find("div", class_="calMonthCurrent")

todays_date = datetime.date.today()

pink_sack = []
for div in pink:
    n = div.text
    pink_sack.append(n)
pink_sack = list(map(int, pink_sack))

black_sack = []
for div in black:
    n = div.text
    black_sack.append(n)
black_sack = list(map(int, black_sack))

color_sack = []
color_sack = [None] * (len(pink_sack) + len(black_sack))
if pink_sack[0] < black_sack[0]:
    color_sack[::2] = pink_sack
    color_sack[1::2] = black_sack
else:
    color_sack[::2] = black_sack
    color_sack[1::2] = pink_sack

second_month_start = [
    i for i in range(len(color_sack) - 1) if (color_sack[i] > color_sack[i + 1])
]

second_month_start = int("".join(map(str, second_month_start))) + 1

current_month_list = color_sack[:(second_month_start)]

next_month_list = color_sack[(second_month_start):]

for n in current_month_list:
    if n > (todays_date.day):
        nrd = n
        break
else:
    nrd = next_month_list[0]


if todays_date.day in current_month_list:
    todays_day()
elif todays_date.month == 12 and nrd == next_month_list[0]:
    todaysmonth = todays_date.month % 12 + 1
    todaysyear = todays_date.year + 1
    day = calendar.weekday((todaysyear), (todaysmonth), (nrd))
    print(
        f"Next rubbish day is {(calendar.day_name[day])} the {(ord(nrd))}"
        + (" and is Pink" if nrd() in pink_sack else " and is Black")
    )
elif todays_date.month != 12 and nrd == next_month_list[0]:
    todaysmonth = todays_date.month + 1
    todaysyear = todays_date.year
    day = calendar.weekday((todaysyear), (todaysmonth), (nrd))
    print(
        f"Next rubbish day is {(calendar.day_name[day])} the {(ord(nrd))}"
        + (" and is Pink" if nrd in pink_sack else " and is Black")
    )
else:
    day = calendar.weekday((todays_date.year), (todays_date.month), (nrd))

    print(
        f"Next rubbish day is {(calendar.day_name[day])} the {(ord(nrd))}"
        + (" and is Pink" if nrd in pink_sack else " and is Black")
    )

Leeds City Council

A friend pointed me towards this project a while ago and since I've started learning/using Python in a professional capacity, I thought I'd take a crack at adding my local council to the repo. Unfortunately, however, it seems that their website has Incapsula as a firewall, which returns a bot detection response (like the one here).

We do have an actual bin app though that's not made by the council and seems to be getting its data from Data Mill North via two CSV files. I thought about taking the same approach with this, but thought I'd ask permission first, since I know this project is more gained towards using BeautifulSoup.

I've started in my own repo using the CouncilClass like the other scripts - the only things that differ so far is the passed URL doesn't do anything, though I'll need to do something to handle PAON/postcode entry (either adding input prompts or passing as command line arguments somehow).

Is this a viable approach, or would I be better contributing by trying the outstanding requests?

Contributor access to write on wiki

Hey @robbrad, just wondered if it was possible to give contributors write permissions to the wiki (totally understandable if not, I don't mind submitting a PR instead ๐Ÿ˜). I'd like to use it to provide a list of supported councils, as well as the necessary commands to run the script (as opposed to another markdown file!)

Syntax Error

Hi, I think I have this working from a Home Assistant / Python point of view, however when I run I get a Python Syntax error

Syntax errors detected :

Line 26:
data[f'{binType}'] = f'{binCollection}'
^
SyntaxError: invalid syntax

I know next to nothing about coding so I tried checking here https://extendsclass.com/python-tester.html and it shows the same error. I checked the other bin collection scripts and the one that is similar to this throws the same error, but the ones that are completely different doesn't. I checked pythonbuddy.com and it said "Format strings are only supported in Python 3.6 and greater (, line 26)" however I have 3.7 installed as Home Assistant required it and the venv was set up using it. I tried to shebang the specific version 3.7.3 and it still threw the syntax error. Any idea?

Originally posted by @Mod74 in #3 (comment)

Add wiki entries

Add instructions for the following councils:

  • York
  • East Riding
  • Windsor and Maidenhead (once complete)
  • Castlepoint

City of York Council

Name of Council

City of York Council

Example Postcode

YO24 4PB

Additional Information

This would be a good first issue for anyone new to Python/scraping APIs, as York provide their own API for scraping bin data easily. Requires a UPRN rather than a postcode.

Link to the API documentation:

https://storage.googleapis.com/dx-york-production/ckan/resources/91b2852b-c779-4f4d-9ef4-3c2fdfa2a565/waste-services-api-v-3.0.0.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=60&X-Amz-Credential=GOOG1EZ6DEPSOK7DRKXPDSBDQNJKTDCVUD65PV6GN5JNEA76IMWPISTE5BIHY%2F20220723%2Feurope-west1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20220723T231428Z&X-Amz-Signature=4dd34cb7ad4a80d79c4cad9238b708aac66afcbebabf87cb733c05d0974e098e

Link to the waste collection date checker:

https://myaccount.york.gov.uk/bin-collections

Peterborough City Council

I have linked below my postman collections, however this should be really easy to implement.

Postcode - PE15RY
UPRN     - 10008051981

Run in Postman

Line endings

Hi Rob,

I'm having a hack around with the scripts, but am having line ending issues, specifically adding the shebang #!/usr/bin/env python3 to collect_data.py in develop. It looks like the master branch uses LF endings, but the develop has switched to CRLF. Was this a deliberate choice? (If so, HuntingdonDistrictCouncil.py in develop appears to be LF endings).

I'm totally unfamiliar with git/github's line end mangling and the expected formatting in repo and working copy, except on *nix files must be LF for shebangs to work. If it wasn't intentional, I think I've sorted it in aejh/UKBinCollectionData@ 46e00c9 (from here: https://www.aleksandrhovhannisyan.com/blog/crlf-vs-lf-normalizing-line-endings-in-git/#a-simple-gitattributes-config), can make a pull request if you think I'm barking up the right tree!

Cheers, Al.

Missing Module

Hi there,

Now I'm 99.9% sure this is a user error issue but thought I'd ask anyways.

I've copied the repo to a ubuntu WSL vm thing on my pc and updated/installed the scripts according to the poetry file, but when running the script for my council that you guys kindly created the other week I get a missing module error

Traceback (most recent call last):
File "/root/UKBinCollectionData/uk_bin_collection/uk_bin_collection/collect_data.py", line 6, in
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
ModuleNotFoundError: No module named 'uk_bin_collection'

My HA install is running on a separate machine running a Proxmox server

any help/guidance would be smashing

Rushcliffe Borough Council

Name of Council

Rushcliffe Borough Council

Example Postcode

ng13 8tz

Additional Information

No response

Unit test broken

Root folder in unit test breaks the module import

ref: 4173300

Moving back to
from uk_bin_collection.common import *

from recent commit

from uk_bin_collection.uk_bin_collection.common import *

Seams to work fine

Unit tests run with : poetry run coverage run -m pytest

and also work on VS Code with the venv set

image

Improve documentation

As an end user I would like to have the ability to learn how to run the library/debug/develop

consider read the docs (RST) or readme.md / build.md etc

Wakefield Council

Hi

Any chance of getting Wakefield Council added please ?

Thanks

Martyn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.