From 9e56fcab2879ce564811569d0a6090cda6376faa Mon Sep 17 00:00:00 2001 From: Lance0095 Date: Thu, 16 Mar 2023 15:49:32 +0100 Subject: [PATCH] Added comments and documentation --- .../service/Samiljo_se_wastetype_searcher.py | 40 +++++++++++++------ doc/source/samiljo_se.md | 15 +++++++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/service/Samiljo_se_wastetype_searcher.py b/custom_components/waste_collection_schedule/waste_collection_schedule/service/Samiljo_se_wastetype_searcher.py index dc47b94b..8eea9deb 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/service/Samiljo_se_wastetype_searcher.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/service/Samiljo_se_wastetype_searcher.py @@ -13,6 +13,21 @@ TITLE = "Samverkan Återvinning Miljö (SÅM)" DESCRIPTION = "Source script for samiljo.se" URL = "https://www.samiljo.se" +"""requirements +alive_progress +beautifulsoup4 +requests +urllib3 +""" + + +# Will take arguments --city, --street, and --char +parser = argparse.ArgumentParser(description="Searches for new bin types not yet included in NAME_MAP. Searches all addresses in the database if not otherwise specified.") +parser.add_argument("--street", type=str, help="Specify a street adress or part of it.") +parser.add_argument("--city", type=str, help="Specify a city.") +parser.add_argument("--char", type=str, help="exclude characters from search (eg \"abcdef\")") +args = parser.parse_args() + API_URLS = { "address_search": "https://webbservice.indecta.se/kunder/sam/kalender/basfiler/laddaadresser.php", "collection": "https://webbservice.indecta.se/kunder/sam/kalender/basfiler/onlinekalender.php", @@ -58,11 +73,6 @@ retry_codes = [ HTTPStatus.GATEWAY_TIMEOUT, ] -parser = argparse.ArgumentParser() -parser.add_argument("--street", type=str, required=False) -parser.add_argument("--city", type=str, required=False) -parser.add_argument("--used_char", type=str, required=False) -args = parser.parse_args() NEW_NAME_MAP = {} @@ -123,13 +133,12 @@ def waste_searcher(arg1): # sourcery skip: use-fstring-for-concatenation #used_char = ["a", "b",] used_char = [] checked_addresses = [] -found_char = 0 alphabet = "abcdefghijklmnopqrstuvwxyzåäö" if args.street or args.city: used_char = [] elif args.used_char: - used_char = list(args.used_char) + used_char = list(args.char) bar_count = len(alphabet) # - len(used_char) @@ -151,10 +160,10 @@ with alive_bar(bar_count) as bar: new_addressarray=adresslist.text.lower().splitlines() for line in new_addressarray: # if line contains an alredy searched character then don"t write it - found_char=0 + found_char = 0 for x in used_char: if x in line.strip("\n"): - found_char=1 + found_char = 1 if found_char == 0: checked_addresses.append(line) #add searched character to used_char @@ -197,6 +206,13 @@ with alive_bar(total) as bar: """ for thread in threads_list: thread.join() """ - -for line in NEW_NAME_MAP: - print(line) \ No newline at end of file +if NEW_NAME_MAP: + for line in NEW_NAME_MAP.values(): + print(line) + print("Map these new waste types to a common name using https://samiljo.se/avfallshamtning/hamtningskalender in conjunction with addresses above. Add the new common name to the NAME_MAP in samiljo_se.py and Samiljo_se_wastetype_searcher.py") +elif args.city and args.street: + print( + f"The waste types for {args.street}, {args.city} are alredy included in the NAME_MAP." + ) +else: + print("Found no new waste types.") \ No newline at end of file diff --git a/doc/source/samiljo_se.md b/doc/source/samiljo_se.md index 63b949d3..96472095 100644 --- a/doc/source/samiljo_se.md +++ b/doc/source/samiljo_se.md @@ -39,3 +39,18 @@ waste_collection_schedule: The source argument is the street including number and the city to the house with waste collection. The address can be tested [here](https://samiljo.se/avfallshamtning/hamtningskalender/). + +## How to add new waste types + +If your address are missing any waste types that shows in the [Hämtningskalender](https://samiljo.se/avfallshamtning/hamtningskalender/). Then there might be missing mappings in the NAME_MAP. +1. Run Samiljo_se_wastetype_searcher.py for the specific address or without arguments to scan all addresses in the database. +Examples of valid command below. +```cli +> samiljo_se_wastetype_searcher.py --street "Storgatan 1" --city "Burseryd" +> samiljo_se_wastetype_searcher.py --city "Burseryd" +> samiljo_se_wastetype_searcher.py --street "Storgatan 1" +> samiljo_se_wastetype_searcher.py +``` +2. Missing mappings will be returned together with an address. +3. Use the [Hämtningskalender](https://samiljo.se/avfallshamtning/hamtningskalender/) to extract the corresponding common name to the new wastetype. +4. Add the new types to the NAME_MAP and optionaly to the ICON_MAP in samiljo_se.py and samiljo_se_wastetype_searcher.py. \ No newline at end of file