| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- from config import Config
- conf = Config()
- import requests
- url = conf.weather_base_url
- headers = {"X-QW-Api-Key": conf.weather_api_key, "Accept-Encoding": "gzip, deflate, br"}
- chengdu = [
- 101270101, 101270102, 101270103, 101270104, 101270105,
- 101270106, 101270107, 101270108, 101270109, 101270110,
- 101270111, 101270112, 101270113, 101270114, 101270115,
- 101270116, 101270117, 101270118, 101270119, 101270120,
- 101270121
- ]
- beijing = [
- 101010100,
- 101010200,
- 101010300,
- 101010400,
- 101010500,
- 101010600,
- 101010700,
- 101010800,
- 101010900,
- 101011000,
- 101011100,
- 101011200,
- 101011300,
- 101011400,
- 101011500,
- 101011600,
- 101011700
- ]
- params = {
- 'location': '101270101'
- }
- def main():
- """手动验证天气 API;导入本文件不会发送请求。"""
- if not conf.weather_api_key or conf.weather_api_key.startswith("your_"):
- raise RuntimeError("请先在 .env 中填写自己的 QWEATHER_API_KEY。")
- if conf.weather_api_host == "your_qweather_host":
- raise RuntimeError("请先在 .env 中填写自己的 QWEATHER_API_HOST。")
- response = requests.get(url, headers=headers, params=params, timeout=15)
- response.raise_for_status()
- print(f"状态码: {response.status_code}")
- print("响应内容:")
- print(response.text)
- if __name__ == "__main__":
- main()
|