#Weather App Trouble

1 messages · Page 1 of 1 (latest)

shadow nexus
#

Below is my file structure:

├── __pycache__
│   ├── config.cpython-311.pyc
│   └── run.cpython-311.pyc
├── app
│   ├── __init__.py
│   ├── __pycache__
│   ├── routes.py
│   └── templates
├── config.py
├── run.py
└── venv
    ├── bin
    ├── include
    ├── lib
    └── pyvenv.cfg```
For one, any changes I should make this to conform to standards?

Anyways, I am making a Weather App. Super simple. I'm using the OpenWeatherAPI (https://openweathermap.org/) to do so. I have set up the files (please let me know if you need specific code to one I didn't provide) and my API is not retrieving any data. I have no experience with using external APIs.. any help is appreciated!

Currently, the error message is rendering because it is status 401.

Edit: The code below is to the `routes.py` file
surreal kernel
#

Are you sure of the URL format? There is a multiple way to set the url, maybe the url has an issue and cannot fetch the data from the API. Also, how does your config file looks like? Maybe sure you do not have typo in your token variable (and make sure it is set also)

shut tide
# shadow nexus Below is my file structure: ```. ├── __pycache__ │ ├── config.cpython-311.pyc ...

First, I would make put everything related to openweather request into a service instead of directly in the controller. If you want to make it MVC there's a bunch of stuff that can be modified. However, for this project it wouldn't be the end of the world to keep it simpler. That said, don't forget to create a static folder containing your css, images, js, etc (in separated folder ofc)

shut tide
#

This should all be set in a .env

#

Loaded by your config

#

You can look at @fervent steeple config although it's slighlty more complex that you need to have

shadow nexus
# shut tide This should all be set in a `.env`

I am getting this error when I try to run my program now... any ideas? I pip installed python-dotenv and it looks fine... not sure what the issue is

ModuleNotFoundError: No module named 'dotenv'

#
from dotenv import load_dotenv
import os

load_dotenv()
API_KEY = os.getenv('API_KEY')

def get_lat_long(city_name, state_code, country_code, API_KEY):
    response = requests.get(f'http://api.openweathermap.org/geo/1.0/direct?q={city_name},{state_code},{country_code}&limit=&appid={API_KEY}')
    
    print(response.json())

get_lat_long('New York', 'NY', 'US', API_KEY)```
surreal kernel
#

try pip3 install python-dotenv

shadow nexus
shut tide
#

it should be python-dotenv. Did you run that in your venv? It need to be installed in your venv

surreal kernel
#

I edited

shadow nexus
#

dotend? and yes i did

surreal kernel
#

dotenv is the package outside venv

shut tide
#

Typo

surreal kernel
#

It might be the cause of your error

shadow nexus
#

oh...

#

i need to cd venv? or is this fine bc it's running on venv

surreal kernel
#
pip3 uninstall dotenv
pip3 uninstall python-dotenv
pip3 install python-dotenv```
surreal kernel
shadow nexus
#

no luck

#

welp, it worked when i ran it through the terminal... guess it's just an issue with my run code lol

surreal kernel
shut tide
#

Try deactivating and reactivating your venv

shadow nexus
#

it worked in the terminal. it was just an issue with my VSCode "Run Code" thing

shut tide
#

Oh boy

#

don't use that

shadow nexus
#

but i normally just run my script thru terminal anyways for python it's all good

#

haha yeah

shut tide
#

VS Code Run is 💩

surreal kernel
#

Terminal is your friend

shadow nexus
#

it was great for java, but yeah python i've noticed it's horrendous

shut tide
#

Even the VS Code terminal is worthless

surreal kernel
#

Never use any UI, it's often crap.

shadow nexus
#

oh... yeah i use that 😄

surreal kernel
shadow nexus
#

success.

#

should i keep this thread open for general project questions? i'm just gonna finish it today. or should i just close and reopen for new Qs

shut tide
shadow nexus
shadow nexus
#

Weather App Trouble

shut tide
#

Everything is going well?

#

Have you looked into MVC? As I said, it might not be necessary for this project but it's also a good time to try to implement this