File size: 508 Bytes
221e2fc
 
 
 
 
 
 
 
a8fdef3
 
 
 
221e2fc
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)

API_KEY = "6d0b5a223205f8e88b2b9d45a0ad532a"

@app.route("/get_weather", methods=["GET"])
@app.route("/")
def index():
    return "✅ Weather API is running!"

def get_weather():
    city = request.args.get("city")
    res = requests.get(f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric")
    return jsonify(res.json())

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)