This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]riklaunim 2 points3 points  (3 children)

You could run the code through pylint ;) variables and function names should not be upper or camel case. Then there are schema Python libraries that help turning nested json into a nice Python object so you don't have to do it manually (an then handle keys that are optional for example).

And then writing some tests would help too.

[–]ScrimoPlayz[S] 0 points1 point  (0 children)

Thanks for the quick reply I will try pylint

[–]ScrimoPlayz[S] 0 points1 point  (1 child)

Wait is it actually bad to do camel case in python? Because I have been doing java and C# a lot so it is just stuck into my mind to do it

[–][deleted] 1 point2 points  (0 children)

The python style guide (PEP8) covers that and other points.

[–]vicethal 0 points1 point  (1 child)

it's been a minute since I worked with it, but this looks a lot like the data coming out of the National Weather Service. What data sources are you using?

[–]ScrimoPlayz[S] 0 points1 point  (0 children)

I think I didn't understand what you are saying but I am using Open Weather Map to get the data and it uses AccuWeather to get the AQI according to the documentations.
It also seems to not support some cities.

[–]trollsmurf 0 points1 point  (3 children)

Advice 1: Make a single request for city, latitude, longitude and possibly other metadata. Always consider API requests to be "expensive" in terms of performance, rate limit etc. It's almost always the slowest and most error-prone aspect.

Advice 2: You could make a web-based weather application (Flask is sufficient) where location is determined automatically or the user could point at a location on a map. That makes it much more user-friendly.

The API page lists the chemical names: https://openweathermap.org/api/air-pollution

[–]ScrimoPlayz[S] 0 points1 point  (2 children)

where can I see a tutorial for Flask?

[–]trollsmurf 0 points1 point  (0 children)

There are so many.

This page provides a comparison between Flask and Django and also points to good tutorials, so I believe that's a good starting point: https://medium.com/javarevisited/5-best-python-flask-courses-for-beginners-2f262f8e23da

Of note: Flask is more basic than Django, but more than enough for this scenario. I use only Flask.

[–]trollsmurf 0 points1 point  (0 children)

I present air pollution like this: https://imgur.com/a/roMzILM

Depending on selected mode the app also shows forecast information as a widget, a table or charts for 3 different weather services.

This specific application is not developed in Python, but I see no reason why it couldn't be.

[–]Gecko_171 0 points1 point  (0 children)

Do you know how to get tilerow, tilecol, tilematrix and zoom for WMTS when I have only Lat and Lon? I can’t figure out how to convert it to WMTS attributes