use black to format code

This commit is contained in:
mampfes
2020-12-31 13:07:36 +01:00
parent 6a4c579bb3
commit ff7218e846
16 changed files with 86 additions and 140 deletions

View File

@@ -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:

View File

@@ -48,7 +48,7 @@ class Customize:
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
@@ -56,7 +56,7 @@ def filter_function(entry: CollectionAppointment, customize:Dict[str,Customize])
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:
@@ -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
@@ -180,7 +180,7 @@ class Scraper:
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
@@ -194,7 +194,7 @@ class Scraper:
return
# create source
source = source_module.Source(**kwargs) # type: ignore
source = source_module.Source(**kwargs) # type: ignore
# create scraper
g = Scraper(source, customize)

View File

@@ -26,6 +26,7 @@ SERVICE_DOMAINS = {
"wml2": "EGW Westmünsterland",
}
class AbfallnaviDe:
def __init__(self, service_domain):
self._service_domain = service_domain
@@ -135,7 +136,6 @@ class AbfallnaviDe:
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)
@@ -151,5 +151,6 @@ def main():
roe = AbfallnaviDe("roe")
print(roe.get_dates("Roetgen", "Am Sportplatz", "2"))
if __name__ == "__main__":
main()

View File

@@ -8,23 +8,20 @@ from ..helpers import CollectionAppointment
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",

View File

@@ -7,14 +7,7 @@ from ..service.ICS import ICS
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:

View File

@@ -7,38 +7,38 @@ from ..service.ICS import ICS
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",
],
},
}
@@ -57,7 +57,9 @@ class Source:
# 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
@@ -74,10 +76,7 @@ class Source:
}
# 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)

View File

@@ -4,25 +4,22 @@ from ..service.AbfallnaviDe import AbfallnaviDe
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"
"hausnummer": "7",
},
"Lindlar, Aggerweg":
{
"Lindlar, Aggerweg": {
"service": "lindlar",
"ort": "Lindlar",
"strasse": "Aggerweg"
"strasse": "Aggerweg",
},
"Roetgen, Am Sportplatz 2":
{
"Roetgen, Am Sportplatz 2": {
"service": "roe",
"ort": "Roetgen",
"strasse": "Am Sportplatz",
"hausnummer": "2"
"hausnummer": "2",
},
}

View File

@@ -7,13 +7,7 @@ from ..helpers import CollectionAppointment
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:

View File

@@ -9,13 +9,11 @@ from ..service.ICS import ICS
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",
},
@@ -62,9 +60,9 @@ class Source:
"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",
@@ -82,8 +80,8 @@ class Source:
"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

View File

@@ -5,7 +5,7 @@ from ..helpers import CollectionAppointment
DESCRIPTION = "Example scraper"
URL = ""
TEST_CASES:Dict[str, Dict[str, str]] = {}
TEST_CASES: Dict[str, Dict[str, str]] = {}
class Source:

View File

@@ -9,24 +9,19 @@ from ..service.ICS import ICS
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__)
@@ -34,8 +29,7 @@ TEST_CASES = {
.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__)
@@ -43,12 +37,10 @@ TEST_CASES = {
.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"
},
}

View File

@@ -8,20 +8,11 @@ from ..helpers import CollectionAppointment
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

View File

@@ -9,23 +9,17 @@ from ..service.ICS import ICS
DESCRIPTION = "Source for Muellmax.de based services."
URL = "https://www.muellmax.de"
TEST_CASES = {
"Frankfurt, Achenbachstrasse 5":
{
"Frankfurt, Achenbachstrasse 5": {
"service": "Fes",
"mm_frm_str_sel": "Achenbachstraße",
"mm_frm_hnr_sel": "60596;Sachsenhausen;5;",
},
"Rhein-Sieg-Kreis, Alfter":
{
"Rhein-Sieg-Kreis, Alfter": {
"service": "Rsa",
"mm_frm_ort_sel": "Alfter",
"mm_frm_str_sel": "Ahrweg (105-Ende/94-Ende)",
},
"Münster, Achatiusweg":
{
"service": "Awm",
"mm_frm_str_sel": "Achatiusweg"
},
"Münster, Achatiusweg": {"service": "Awm", "mm_frm_str_sel": "Achatiusweg"},
}

View File

@@ -6,11 +6,7 @@ from ..service.ICS import ICS
DESCRIPTION = "Source for Stadtreinigung.Hamburg based services."
URL = "https://www.stadtreinigung.hamburg"
TEST_CASES = {
"Hamburg":
{
"asId": 5087,
"hnId": 113084
},
"Hamburg": {"asId": 5087, "hnId": 113084},
}

View File

@@ -7,13 +7,7 @@ from ..helpers import CollectionAppointment
DESCRIPTION = "Source for stuttgart.de based services."
URL = "https://service.stuttgart.de/lhs-services/aws/"
TEST_CASES = {
"Im Steinengarten 7":
{
"street": "Im Steinengarten",
"streetnr": 7
}
}
TEST_CASES = {"Im Steinengarten 7": {"street": "Im Steinengarten", "streetnr": 7}}
# Parser for HTML checkbox

View File

@@ -7,8 +7,10 @@ import sys
import inquirer
import requests
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
PACKAGE_PARENT = ".."
SCRIPT_DIR = os.path.dirname(
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))
)
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from service.AbfallnaviDe import SERVICE_DOMAINS, AbfallnaviDe # isort:skip
@@ -46,7 +48,7 @@ def main():
inquirer.List(
"city_id",
choices=convert_dict_to_array(cities),
message="Select municipality [Kommune/Ort]"
message="Select municipality [Kommune/Ort]",
)
]
city_id = inquirer.prompt(questions)["city_id"]
@@ -56,9 +58,7 @@ def main():
streets = api.get_streets(city_id)
questions = [
inquirer.List(
"street_id",
choices=convert_dict_to_array(streets),
message="Select street"
"street_id", choices=convert_dict_to_array(streets), message="Select street"
)
]
street_id = inquirer.prompt(questions)["street_id"]