-
Create your project
-
You need requirements.txt file to install the dependencies
- flask
-
pip3 install -r requirements.txt
-
python3 -m pip install -r requirements.txt
-
-
Create a simple Flask app
- Create a file called app.py and add the following code:
from flask import Flask, jsonify, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('hello.html')
if __name__ == '__main__':
app.run(debug=True,port=5000)- Create a simple HTML file
- Create a folder called templates and add a file called hello.html with the following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Hello, World!</h1>
<p>This is a simple Flask app.</p>
</div>
</body>
</html>-
Install requests library
- pip install requests
-
Create a file called test.py and add the following code:
import requests
import json
# Define the endpoint URL
url = "https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.get(url, headers=headers)
# Print the response
print(response.status_code)
print(response.json())