Added comments and documentation

This commit is contained in:
Lance0095
2023-03-16 15:49:32 +01:00
parent c2a48c9840
commit 9e56fcab28
2 changed files with 43 additions and 12 deletions

View File

@@ -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)
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.")

View File

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