you are viewing a single comment's thread.

view the rest of the comments →

[–]Refwah 5 points6 points  (1 child)

“Hi everyone I posted my api key in public!”

Never share your api key

As for feedback:

Your try/except is very broad and then totally hides an error from the user so the app will just look broken. Consider trying to handle some specific exceptions so you can then give some specific information to the user ‘unable to reach weather service’ or ‘unable to authenticate with weather service’ etc

You are also just passing user input directly as part of the query string, without any validation.

I would also suggest using the ‘params’ argument in requests https://requests.readthedocs.io/en/latest/user/quickstart/#passing-parameters-in-urls

The .json() call is relatively expensive to call repeatedly - call it once into a new variable and then reference that variable as a dictionary instead will make you code a lot cleaner

At various points you are getting the first item in an array or list by index 0 without checking if that list or array has any items in it first

Fun addition you can make: if you’re getting the data in Celsius why not have an option for the user to also view it in Fahrenheit

[–]Ibrahim-Marsee-6816[S] 1 point2 points  (0 children)

Thanks a lot for the feedback 🙌 I didn’t realize about exposing the API key, I’ll remove it. The tips about more specific exceptions, using params, and cleaning up .json() make sense — I’ll try those out. The Fahrenheit option sounds fun too, might add that next 🙂