Skip to content

天气查询后端开发

实战需求

点击查看实战详情

实现代码

import requests
# 导入 Flask 模块
from flask import Flask
# 创建 Flask 应用程序实例
app = Flask(__name__)

# 定义路由
@app.route("/")
# 定义视图函数
def index():
    # 返回响应
    return "<h1>霍格沃兹天气查询平台</h1>"

@app.route("/weather/")
def city_weather():
    weather_info = {
        "city": "济南",
        "date": "2022-05-05",
        "week": "星期四",
        "update_time": "22:38",
        "wea": "多云", 
        "wea_img": "yun",
        "tem": "25",
        "tem_day": "30", 
        "tem_night": "23", 
        "win": "南风", 
        "win_speed": "3级",
        "win_meter": "19km/h",
        "air": "53", 
        "pressure": "987", 
        "humidity": "27%" 
        }
    return weather_info

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5008, debug=True)