-
-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support fo "Renhållningen Kristianstad" in Kristianstad, Sweden #2741
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you name the source krab_se? We typically name the source after the website ULR so renhallningen_kristianstad_se
here.
Did you do any testing before submitting this? The source is fundamentally broken at multiple points. Please test your source using the test script (test_sources.py) before submitting a PR
params = [{"query": self._street_address}] | ||
headers = {"Module": "universal", | ||
"Accept": "application/json, text/plain, */*", | ||
"Unit": "dd905ce7-b16d-4422-be36-564169af4035"} | ||
response = requests.get( | ||
"https://api-universal.appbolaget.se/waste/addresses/search", | ||
headers=headers, | ||
params=urllib.parse.urlencode(params), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work you cannot urllib.parse.urlencode
a list, You don't need to encode anything just make your params
a dict and pass it as params
the request's library does the converting for you (probably with the same method)
params = [building_id] | ||
headers = {"Module": "universal", | ||
"Accept": "application/json, text/plain, */*", | ||
"Unit": "dd905ce7-b16d-4422-be36-564169af4035"} | ||
response = requests.get( | ||
"https://api-universal.appbolaget.se/waste/addresses", | ||
headers=headers, | ||
params=urllib.parse.urlencode(params), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
building_id is not passed as a param at all but as part of the url:
response = requests.get(
"https://api-universal.appbolaget.se/waste/addresses" +building_id,
headers=headers
)
params=urllib.parse.urlencode(params), | ||
) | ||
|
||
data = json.loads(response.text)["services"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its data = json.loads(response.text)["data"]["services"]
if not building_id: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please raise an Exception instead of just returning [], So There is an error message in the GUI while configuring or in the logs if this happens with an already configured source
First of all naming conventions and naming. I'm sorry for the code as it's really so many things that's wrong there. There's no other way of sayng it than it's totally FU. |
Added support for "Renhållningen Kristianstad" in Sweden to HACS waste collection service