This project sets up a basic web server using Flask that exposes an API endpoint to greet visitors and provide the current temperature of their location based on their IP address.
- Get the client's IP address.
- Determine the client's location (city) using their IP address.
- Fetch the current temperature for the client's location.
- Return a JSON response with the client's IP, location, and greeting message.
Query Parameters:
visitor_name
(optional): The name of the visitor. Defaults to "Guest" if not provided.
Response:
{
"client_ip": "127.0.0.1",
"location": "New York",
"greeting": "Hello, Guest! The temperature is 11 degrees Celsius in New York."
}
To run this project, you need to have the following installed:
- Python 3.x
- Flask
- Requests
- Clone the repository:
git clone https://github.com/Ibrahim-mj/hng11-stage-one.git
- Change into the project directory:
cd hng11-stage-one
- Install the required dependencies:
pip install -r requirements.txt
- Add your seceret key and openweather api key to the .env file
- Start the Flask server:
flask run
-
Open your browser and navigate to
http://localhost:5000/hello
to access the API endpoint. -
You can also pass a
visitor_name
query parameter to customize the greeting message:
http://localhost:5000/api/hello?visitor_name=Mark