Skip to content

Commit

Permalink
use black to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed Dec 31, 2020
1 parent 6a4c579 commit ff7218e
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
args:
- --safe
- --quiet
files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$
files: ^((custom_components|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v1.16.0
hooks:
Expand Down
12 changes: 6 additions & 6 deletions custom_components/waste_collection_schedule/package/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def __repr__(self):
return f"Customize{{name={self.name}, alias={self.alias}, show={self.show}, icon={self.icon}, picture={self.picture}}}"


def filter_function(entry: CollectionAppointment, customize:Dict[str,Customize]):
def filter_function(entry: CollectionAppointment, customize: Dict[str, Customize]):
c = customize.get(entry.type)
if c is None:
return True
else:
return c.show


def customize_function(entry: CollectionAppointment, customize:Dict[str,Customize]):
def customize_function(entry: CollectionAppointment, customize: Dict[str, Customize]):
c = customize.get(entry.type)
if c is not None:
if c.alias is not None:
Expand All @@ -69,9 +69,9 @@ def customize_function(entry: CollectionAppointment, customize:Dict[str,Customiz


class Scraper:
def __init__(self, source: str, customize:Dict[str,Customize]):
def __init__(self, source: str, customize: Dict[str, Customize]):
self._source = source
self._entries:List[CollectionAppointment] = []
self._entries: List[CollectionAppointment] = []
self._refreshtime = None
self._customize = customize # dict of class Customize

Expand Down Expand Up @@ -180,7 +180,7 @@ def _filter(
return entries

@staticmethod
def create(source_name: str, dir_offset, customize:Dict[str,Customize], kwargs):
def create(source_name: str, dir_offset, customize: Dict[str, Customize], kwargs):
# load source module

# for home-assistant, use the last 3 folders, e.g. custom_component/wave_collection_schedule/package
Expand All @@ -194,7 +194,7 @@ def create(source_name: str, dir_offset, customize:Dict[str,Customize], kwargs):
return

# create source
source = source_module.Source(**kwargs) # type: ignore
source = source_module.Source(**kwargs) # type: ignore

# create scraper
g = Scraper(source, customize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"wml2": "EGW Westmünsterland",
}


class AbfallnaviDe:
def __init__(self, service_domain):
self._service_domain = service_domain
Expand Down Expand Up @@ -135,7 +136,6 @@ def get_dates(self, city, street, house_number=None):
else:
return self.get_dates_by_street_id(street_id)


def _find_in_inverted_dict(self, mydict, value):
inverted_dict = dict(map(reversed, mydict.items()))
return inverted_dict.get(value)
Expand All @@ -151,5 +151,6 @@ def main():
roe = AbfallnaviDe("roe")
print(roe.get_dates("Roetgen", "Am Sportplatz", "2"))


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
DESCRIPTION = "Source for AbfallPlus.de based services. Service is hosted on abfall.io"
URL = "https://www.abfallplus.de"
TEST_CASES = {
"Waldenbuch":
{
"Waldenbuch": {
"key": "8215c62763967916979e0e8566b6172e",
"f_id_kommune": 2999,
"f_id_strasse": 1087,
# "f_abfallarten": [50, 53, 31, 299, 328, 325]
},
"Landshut":
{
"Landshut": {
"key": "bd0c2d0177a0849a905cded5cb734a6f",
"f_id_kommune": 2655,
"f_id_bezirk": 2655,
"f_id_strasse": 763,
# "f_abfallarten": [31, 17, 19, 218]
},
"Schoenmackers":
{
"Schoenmackers": {
"key": "e5543a3e190cb8d91c645660ad60965f",
"f_id_kommune": 3682,
"f_id_strasse": "3682adenauerplatz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@

DESCRIPTION = "Source for Abfall Landkreis Tuebingen"
URL = "https://www.abfall-kreis-tuebingen.de"
TEST_CASES = {
"Dettenhausen":
{
"ort": 3,
"dropzone": 525,
"ics_with_drop": False
}
}
TEST_CASES = {"Dettenhausen": {"ort": 3, "dropzone": 525, "ics_with_drop": False}}


class Source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@

DESCRIPTION = "Source for Abfallwirtschaft Zollernalbkreis based services"
URL = "https://www.abfallkalender-zak.de"
TEST_CASES ={
"Ebingen":
{
TEST_CASES = {
"Ebingen": {
"city": "2,3,4",
"street": "3",
"types": ["restmuell",
"gelbersack",
"papiertonne",
"biomuell",
"gruenabfall",
"schadstoffsammlung",
"altpapiersammlung",
"schrottsammlung",
"weihnachtsbaeume",
"elektrosammlung"
]
"types": [
"restmuell",
"gelbersack",
"papiertonne",
"biomuell",
"gruenabfall",
"schadstoffsammlung",
"altpapiersammlung",
"schrottsammlung",
"weihnachtsbaeume",
"elektrosammlung",
],
},
"Erlaheim":
{
"Erlaheim": {
"city": "79",
"street": "",
"types": ["restmuell",
"gelbersack",
"papiertonne",
"biomuell",
"gruenabfall",
"schadstoffsammlung",
"altpapiersammlung",
"schrottsammlung",
"weihnachtsbaeume",
"elektrosammlung"
]
"types": [
"restmuell",
"gelbersack",
"papiertonne",
"biomuell",
"gruenabfall",
"schadstoffsammlung",
"altpapiersammlung",
"schrottsammlung",
"weihnachtsbaeume",
"elektrosammlung",
],
},
}

Expand All @@ -57,7 +57,9 @@ def fetch(self):
# also get data for next year if we are already in december
try:
entries.extend(
self.fetch_year((now.year + 1), self._city, self._street, self._types)
self.fetch_year(
(now.year + 1), self._city, self._street, self._types
)
)
except Exception:
# ignore if fetch for next year fails
Expand All @@ -74,10 +76,7 @@ def fetch_year(self, year, city, street, types):
}

# get ics file
r = requests.get(
f"https://www.abfallkalender-zak.de",
params=args,
)
r = requests.get(f"https://www.abfallkalender-zak.de", params=args,)

# parse ics file
dates = self._ics.convert(r.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@
DESCRIPTION = "Source for AbfallNavi (= regioit.de) based services"
URL = "https://www.regioit.de"
TEST_CASES = {
"Aachen, Abteiplatz 7":
{
"Aachen, Abteiplatz 7": {
"service": "aachen",
"ort": "Aachen",
"strasse": "Abteiplatz",
"hausnummer": "7"
"ort": "Aachen",
"strasse": "Abteiplatz",
"hausnummer": "7",
},
"Lindlar, Aggerweg":
{
"Lindlar, Aggerweg": {
"service": "lindlar",
"ort": "Lindlar",
"strasse": "Aggerweg"
"strasse": "Aggerweg",
},
"Roetgen, Am Sportplatz 2":
{
"service": "roe",
"ort": "Roetgen",
"strasse": "Am Sportplatz",
"hausnummer": "2"
"Roetgen, Am Sportplatz 2": {
"service": "roe",
"ort": "Roetgen",
"strasse": "Am Sportplatz",
"hausnummer": "2",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@

DESCRIPTION = "Source for AWB Koeln."
URL = "https://www.awbkoeln.de"
TEST_CASES = {
"Koeln":
{
"street_code": 2,
"building_number": 50
}
}
TEST_CASES = {"Koeln": {"street_code": 2, "building_number": 50}}


class Source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
DESCRIPTION = "Source for Berliner Stadtreinigungsbetriebe"
URL = "bsr.de"
TEST_CASES = {
"Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)":
{
"Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)": {
"abf_strasse": "Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)",
"abf_hausnr": 1,
},
"Am Ried, 13467 Berlin (Reinickendorf)":
{
"Am Ried, 13467 Berlin (Reinickendorf)": {
"abf_strasse": "Am Ried, 13467 Berlin (Reinickendorf)",
"abf_hausnr": "11G",
},
Expand Down Expand Up @@ -62,9 +60,9 @@ def fetch(self):
"abf_config_biogut": "on",
"abf_config_wertstoffe": "on",
"abf_config_laubtonne": "on",
#"abf_selectmonth": "5 2020",
#"abf_datepicker": "28.04.2020",
#"listitems":7,
# "abf_selectmonth": "5 2020",
# "abf_datepicker": "28.04.2020",
# "listitems":7,
}
r = requests.post(
"https://www.bsr.de/abfuhrkalender_ajax.php?script=dynamic_kalender_ajax",
Expand All @@ -82,8 +80,8 @@ def fetch(self):
"abf_config_biogut": "on",
"abf_config_wertstoffe": "on",
"abf_config_laubtonne": "on",
#"abf_selectmonth": "5 2020",
#"listitems":7,
# "abf_selectmonth": "5 2020",
# "listitems":7,
}

# create url using private url encoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

DESCRIPTION = "Example scraper"
URL = ""
TEST_CASES:Dict[str, Dict[str, str]] = {}
TEST_CASES: Dict[str, Dict[str, str]] = {}


class Source:
Expand Down
24 changes: 8 additions & 16 deletions custom_components/waste_collection_schedule/package/source/ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,38 @@
DESCRIPTION = "Source for ICS based services"
URL = ""
TEST_CASES = {
"Dortmund, Dudenstr. 5":
{
"Dortmund, Dudenstr. 5": {
"url": "https://www.edg.de/ical/kalender.ics?Strasse=Dudenstr.&Hausnummer=5&Erinnerung=-1&Abfallart=1,2,3,4"
},
"Leipzig, Sandgrubenweg 27":
{
"Leipzig, Sandgrubenweg 27": {
"url": "https://www.stadtreinigung-leipzig.de/leistungen/abfallentsorgung/abfallkalender-entsorgungstermine.html&ical=true&loc=Sandgrubenweg%20%2027&lid=x38296"
},
"Ludwigsburg":
{
"Ludwigsburg": {
"url": "https://www.avl-ludwigsburg.de/fileadmin/Files/Abfallkalender/ICS/Privat/Privat_{%Y}_Ossweil.ics"
},
"Esslingen, Bahnhof":
{
"Esslingen, Bahnhof": {
"url": "https://api.abfall.io/?kh=DaA02103019b46345f1998698563DaAd&t=ics&s=1a862df26f6943997cef90233877a4fe"
},
"Test File":
{
"Test File": {
# Path is used here to allow to call the Source from any location.
# This is not required in a yaml configuration!
"file": Path(__file__)
.resolve()
.parents[1]
.joinpath("test/test.ics")
},
"Test File (recurring)":
{
"Test File (recurring)": {
# Path is used here to allow to call the Source from any location.
# This is not required in a yaml configuration!
"file": Path(__file__)
.resolve()
.parents[1]
.joinpath("test/recurring.ics")
},
"München, Bahnstr. 11":
{
"München, Bahnstr. 11": {
"url": "https://www.awm-muenchen.de/index/abfuhrkalender.html?tx_awmabfuhrkalender_pi1%5Bsection%5D=ics&tx_awmabfuhrkalender_pi1%5Bstandplatzwahl%5D=true&tx_awmabfuhrkalender_pi1%5Bsinglestandplatz%5D=false&tx_awmabfuhrkalender_pi1%5Bstrasse%5D=Bahnstr.&tx_awmabfuhrkalender_pi1%5Bhausnummer%5D=11&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Brestmuell%5D=70024507&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Bpapier%5D=70024507&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Bbio%5D=70024507&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BR%5D=001%3BU&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BP%5D=1%2F2%3BG&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BB%5D=1%2F2%3BU&tx_awmabfuhrkalender_pi1%5Byear%5D={%Y}"
},
"Buxtehude, Am Berg":
{
"Buxtehude, Am Berg": {
"url": "https://abfall.landkreis-stade.de/api_v2/collection_dates/1/ort/10/strasse/90/hausnummern/1/abfallarten/R02-R04-B02-D04-D12-P04-R12-R14-W0-R22-R24-R31/kalender.ics"
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@
DESCRIPTION = "Source for Jumomind.de based services."
URL = "https://www.jumomind.de"
TEST_CASES = {
"ZAW":
{
"service_id": "zaw",
"city_id": 106,
"area_id": 94
},
"Bad Homburg":
{
"service_id": "hom",
"city_id": 1,
"area_id": 461
},
"ZAW": {"service_id": "zaw", "city_id": 106, "area_id": 94},
"Bad Homburg": {"service_id": "hom", "city_id": 1, "area_id": 461},
}


class Source:
def __init__(self, service_id, city_id, area_id):
self._service_id = service_id
Expand Down
Loading

0 comments on commit ff7218e

Please sign in to comment.