开启左侧

动手体验:5min实现第一个智能体——1

[复制链接]
AI小编 发表于 2 小时前 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
作者:CSDN博客
一、动手体验:5min实现第一个智能体

        在本案例中,我们的目标是构建一个能处理分步任务的智能旅行助手。需要解决的用户任务定义为:"你好,请帮我查询一下今天北京的天气,然后根据天气推荐一个合适的旅游景点。"要完成这个任务,智能体必须展现出清晰的逻辑规划能力。它需要先调用天气查询工具,并将获得的观察结果作为下一步的依据。在下一轮循环中,它再调用景点推荐工具,从而得出最终建议。
        为了能从 Python 程序中访问网络 API,我们需要一个 HTTP 库。requests是 Python 社区中最流行、最易用的选择。tavily-python是一个强大的 AI 搜索 API 客户端,用于获取实时的网络搜索结果,可以在官网注册后获取 API。openai是 OpenAI 官方提供的 Python SDK,用于调用 GPT 等大语言模型服务。
角色拆解
    requests —— “通信员” (基础工具)
      定义: 这是一个 HTTP 库。
      作用: 它是 Python 用来“上网”的最基本工具。就像你的浏览器(Chrome/Edge)用来访问网页一样,Python 程序用 requests 来向互联网上的服务器发送请求并获取数据。
      地位: Python 社区的标配,几乎所有涉及网络的程序都会用到它。
    openai —— “大脑” (处理核心)
      定义: OpenAI 的官方 Python 软件开发工具包 (SDK)。
      作用: 它让你的程序能连接到 OpenAI 的服务器,使用 GPT-3.5 或 GPT-4 模型。
      能力: 负责理解用户的意图、进行逻辑推理、总结内容、回答问题。它是整个程序的“智力”来源。
    tavily-python —— “眼睛/搜查员” (信息获取)
      定义: 专门为 AI 设计的搜索引擎接口。
      作用: GPT 的知识是有截止日期的(比如它可能不知道今天的新闻),而 Tavily 可以实时搜索互联网。
      特点: 与普通的 Google 搜索不同,Tavily 返回的是经过整理的、适合 AI 阅读的文本数据,而不是复杂的网页 HTML 代码,这大大提高了 AI 的处理效率。


它们如何协同工作?
        这段文字通常出现在“AI Agent(智能体)”开发的教程或文档中。当你把这三个工具组合在一起时,工作流程通常是这样的:
    用户提问: “今天旧金山的天气怎么样?”
    openai (大脑) 分析: GPT 发现自己不知道今天的实时天气,判断需要搜索网络。
    tavily-python (搜查员) 执行: 接收指令,去互联网上搜索“旧金山 实时天气”,并把搜索结果带回来。
    requests (通信员): 在幕后支持这些数据传输(虽然 openai 和 tavily 库内部封装好了网络请求,但复杂的自定义功能常需配合 requests 使用)。
    最终回答: GPT 结合搜索到的结果,生成最终答案:“今天旧金山多云转晴,气温...”
特性pip installconda install
角色Python 的官方包管理器。跨平台的包管理器 + 环境管理器
仓库来源PyPI (Python Package Index)。拥有最全的 Python 库(超过 30 万个)。Anaconda RepositoryConda-forge。库的数量较少,经过严格筛选和测试。
管理范围只管理 Python 库不仅管理 Python 库,还能管理 C/C++ 库、R 语言包等
依赖处理有时会因为缺少系统级的 C 库(如编译器)而安装失败。擅长处理复杂的底层依赖(比如 NumPy, TensorFlow 需要的 C 库),直接下载编译好的二进制文件,更稳定。
适用场景几乎所有 Python 项目,特别是由于库太新、Conda 没有收录时。科学计算、深度学习环境搭建(避免复杂的编译错误)。
1.1 准备工作
  1. pip install requests tavily-python openai
复制代码
1.2 指令模板

        驱动真实 LLM 的关键在于提示工程(Prompt Engineering)。我们需要设计一个“指令模板”,告诉 LLM 它应该扮演什么角色、拥有哪些工具、以及如何格式化它的思考和行动。这是我们智能体的“说明书”,它将作为system_prompt传递给 LLM。
  1. AGENT_SYSTEM_PROMPT = """
  2. 你是一个智能旅行助手。你的任务是分析用户的请求,并使用可用工具一步步地解决问题。
  3. # 可用工具:
  4. - `get_weather(city: str)`: 查询指定城市的实时天气。
  5. - `get_attraction(city: str, weather: str)`: 根据城市和天气搜索推荐的旅游景点。
  6. # 行动格式:
  7. 你的回答必须严格遵循以下格式。首先是你的思考过程,然后是你要执行的具体行动,每次回复只输出一对Thought-Action:
  8. Thought: [这里是你的思考过程和下一步计划]
  9. Action: 你决定采取的行动,必须是以下格式之一:
  10. - `function_name(arg_name="arg_value")`:调用一个可用工具。
  11. - `Finish[最终答案]`:当你认为已经获得最终答案时。
  12. - 当你收集到足够的信息,能够回答用户的最终问题时,你必须在Action:字段后使用 Finish[最终答案] 来输出最终答案。
  13. 请开始吧!
  14. """
复制代码
1.3 工具1:查询天气
  1. import requests
  2. def get_weather(city: str) -> str:
  3.     """
  4.     通过调用 wttr.in API 查询真实的天气信息。
  5.     """
  6.     # API端点,我们请求JSON格式的数据
  7.     url = f"https://wttr.in/{city}?format=j1"
  8.    
  9.     try:
  10.         # 发起网络请求
  11.         response = requests.get(url)
  12.         # 检查响应状态码是否为200 (成功)
  13.         response.raise_for_status()
  14.         # 解析返回的JSON数据
  15.         data = response.json()
  16.         # 提取当前天气状况
  17.         current_condition = data['current_condition'][0]
  18.         weather_desc = current_condition['weatherDesc'][0]['value']
  19.         temp_c = current_condition['temp_C']
  20.         
  21.         # 格式化成自然语言返回
  22.         return f"{city}当前天气:{weather_desc},气温{temp_c}摄氏度"
  23.         
  24.     except requests.exceptions.RequestException as e:
  25.         # 处理网络错误
  26.         return f"错误:查询天气时遇到网络问题 - {e}"
  27.     except (KeyError, IndexError) as e:
  28.         # 处理数据解析错误
  29.         return f"错误:解析天气数据失败,可能是城市名称无效 - {e}"
复制代码
1.3.1 要点分析——f-string(格式化字符串)

        核心:f代表“Format”(格式化),它的作用是让字符串里的"占位符"变成"活的"。f"..."是告诉Python:"这个字符串里有变量(用花括号包着的),请帮我把它们换成真正的值,然后再拿去用。“
如果没有 f
  1. city = "Beijing"
  2. # 错误写法: 没有 f
  3. url = "https://wttr.in/{city}?format=j1"
  4. print(url)
  5. # 输出结果:https://wttr.in/{city}?format=j1
复制代码
后果: Python会把你写的{city}当作普通的文字字符。当你拿着这个地址去访问往回走那是,网站会以为你要查询一个叫"{city}"的城市,结果当然是查不到或者报错
有 f
  1. city = "Beijing"
  2. url = f"https://wttr.in/{city}?format=j1"
  3. # Python 在后台做了这件事:
  4. # 1. 看到 {city}
  5. # 2. 去找 city 变量的值是什么 (是 "Beijing")
  6. # 3. 把 "Beijing" 塞进去替换掉 {city}
  7. print(url)
  8. # 输出结果: https://wttr.in/Beijing?format=j1
复制代码
       后果:生成了一个动态的、正确的网址。如果下次city变成了"Shanghai",生成的网址就会自动变成.../Shanghai...
1.3.2 要点分析——response.raise_for_status()

        核心:用来检查相应状态码是否为200(成功),成功就继续执行下一段代码,不成功就抛出异常错误!
    意义:在于“早发现,早治疗”
  1. # 发起网络请求
  2.         response = requests.get(url)
  3. # 检查响应状态码是否为200 (成功)
  4.         response.raise_for_status()
复制代码
隐性失败(Silent Failure)

        如果没有这行代码,后果很严重,这种情况叫做"隐性失败"
        场景模拟:假设你要查找一个不存在的城市,比如get_weather(city="Hogwarts")
情况A:没有这行代码
  1. response = requests.get(".../Hogwarts...")
  2. # 此时服务器返回了 404(找不到),并不是 200,
  3. # 但是 requests 默认不会报错, response 变量里存的是一段 HTML 网页代码,写着"404 Not Found"
  4. data = response.json()
  5. # 崩溃!
  6. # 原因: 程序试图把"404 Not Found" 的 HTML 网页当作 JSON 数据来解析
  7. # 报错信息: json.decoder.JSONDecodeError
复制代码
       困惑:看到报错会想:"JSON 解析错误? 是不是我提取数据的逻辑写错了?"(其实不是,是因为你根本没拿到数据,但程序没告诉你)
情况B:有这行代码
  1. response = requests.get(".../Hogwarts...")
  2. response.raise_for_status()
  3. # 报警!
  4. # 发现状态是 404
  5. # 直接抛出 requests.exceptions.HTTPError: 404 Client Error
复制代码
       不会存在情况A这种困惑了,而是看到报错直接写着404 Error,你立刻就明白了:"哦,原来是这个城市的名字写错了,或者是网站挂了。”
1.3.3 要点分析——如何获得一个网站的json格式

方法一:用Python print 出来

        如果你已经拿到了API地址(eg: wttr.in),最直接的办法就是让Python把拿到的数据打印出来,但是普通的print() 打印出来的是一坨乱糟糟的文字,很难看清结构
  1. {'current_condition': [{'FeelsLikeC': '-5', 'FeelsLikeF': '23', 'cloudcover': '0', 'humidity': '58', 'localObsDateTime': '2026-01-18 01:30 PM', 'observation_time': '05:30 AM', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1029', 'pressureInches': '30', 'temp_C': '-4', 'temp_F': '25', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'S', 'winddirDegree': '180', 'windspeedKmph': '4', 'windspeedMiles': '2'}], 'nearest_area': [{'areaName': [{'value': 'Beijing'}], 'country': [{'value': 'China'}], 'latitude': '39.929', 'longitude': '116.388', 'population': '7480601', 'region': [{'value': 'Beijing'}], 'weatherUrl': [{'value': ''}]}], 'request': [{'query': 'Lat 39.91 and Lon 116.39', 'type': 'LatLon'}], 'weather': [{'astronomy': [{'moon_illumination': '1', 'moon_phase': 'New Moon', 'moonrise': '07:24 AM', 'moonset': '04:31 PM', 'sunrise': '07:33 AM', 'sunset': '05:17 PM'}], 'avgtempC': '-5', 'avgtempF': '22', 'date': '2026-01-18', 'hourly': [{'DewPointC': '-12', 'DewPointF': '11', 'FeelsLikeC': '-11', 'FeelsLikeF': '13', 'HeatIndexC': '-7', 'HeatIndexF': '20', 'WindChillC': '-11', 'WindChillF': '13', 'WindGustKmph': '11', 'WindGustMiles': '7', 'chanceoffog': '0', 'chanceoffrost': '86', 'chanceofhightemp': '0', 'chanceofovercast': '90', 'chanceofrain': '100', 'chanceofremdry': '0', 'chanceofsnow': '63', 'chanceofsunshine': '0', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '100', 'diffRad': '0.0', 'humidity': '68', 'precipInches': '0.0', 'precipMM': '0.1', 'pressure': '1030', 'pressureInches': '30', 'shortRad': '0.0', 'tempC': '-7', 'tempF': '20', 'time': '0', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '326', 'weatherDesc': [{'value': 'Light snow'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'E', 'winddirDegree': '97', 'windspeedKmph': '9', 'windspeedMiles': '5'}, {'DewPointC': '-10', 'DewPointF': '14', 'FeelsLikeC': '-11', 'FeelsLikeF': '12', 'HeatIndexC': '-7', 'HeatIndexF': '19', 'WindChillC': '-11', 'WindChillF': '12', 'WindGustKmph': '9', 'WindGustMiles': '6', 'chanceoffog': '0', 'chanceoffrost': '86', 'chanceofhightemp': '0', 'chanceofovercast': '93', 'chanceofrain': '100', 'chanceofremdry': '0', 'chanceofsnow': '72', 'chanceofsunshine': '0', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '100', 'diffRad': '0.0', 'humidity': '80', 'precipInches': '0.0', 'precipMM': '0.1', 'pressure': '1031', 'pressureInches': '30', 'shortRad': '0.0', 'tempC': '-7', 'tempF': '19', 'time': '300', 'uvIndex': '0', 'visibility': '5', 'visibilityMiles': '3', 'weatherCode': '332', 'weatherDesc': [{'value': 'Moderate snow'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'E', 'winddirDegree': '88', 'windspeedKmph': '7', 'windspeedMiles': '4'}, {'DewPointC': '-10', 'DewPointF': '13', 'FeelsLikeC': '-11', 'FeelsLikeF': '12', 'HeatIndexC': '-8', 'HeatIndexF': '18', 'WindChillC': '-11', 'WindChillF': '12', 'WindGustKmph': '9', 'WindGustMiles': '5', 'chanceoffog': '0', 'chanceoffrost': '85', 'chanceofhightemp': '0', 'chanceofovercast': '90', 'chanceofrain': '100', 'chanceofremdry': '0', 'chanceofsnow': '66', 'chanceofsunshine': '0', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '100', 'diffRad': '0.0', 'humidity': '81', 'precipInches': '0.0', 'precipMM': '0.1', 'pressure': '1031', 'pressureInches': '30', 'shortRad': '0.0', 'tempC': '-8', 'tempF': '18', 'time': '600', 'uvIndex': '0', 'visibility': '5', 'visibilityMiles': '3', 'weatherCode': '332', 'weatherDesc': [{'value': 'Moderate snow'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'E', 'winddirDegree': '88', 'windspeedKmph': '6', 'windspeedMiles': '4'}, {'DewPointC': '-12', 'DewPointF': '10', 'FeelsLikeC': '-9', 'FeelsLikeF': '16', 'HeatIndexC': '-7', 'HeatIndexF': '19', 'WindChillC': '-9', 'WindChillF': '16', 'WindGustKmph': '5', 'WindGustMiles': '3', 'chanceoffog': '0', 'chanceoffrost': '85', 'chanceofhightemp': '0', 'chanceofovercast': '83', 'chanceofrain': '0', 'chanceofremdry': '0', 'chanceofsnow': '82', 'chanceofsunshine': '0', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '100', 'diffRad': '29.8', 'humidity': '68', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1033', 'pressureInches': '31', 'shortRad': '62.0', 'tempC': '-7', 'tempF': '19', 'time': '900', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '311', 'weatherDesc': [{'value': 'Light freezing rain'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'ESE', 'winddirDegree': '119', 'windspeedKmph': '4', 'windspeedMiles': '2'}, {'DewPointC': '-12', 'DewPointF': '10', 'FeelsLikeC': '-6', 'FeelsLikeF': '21', 'HeatIndexC': '-5', 'HeatIndexF': '24', 'WindChillC': '-6', 'WindChillF': '21', 'WindGustKmph': '4', 'WindGustMiles': '3', 'chanceoffog': '0', 'chanceoffrost': '84', 'chanceofhightemp': '0', 'chanceofovercast': '94', 'chanceofrain': '0', 'chanceofremdry': '85', 'chanceofsnow': '0', 'chanceofsunshine': '16', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '82', 'diffRad': '97.3', 'humidity': '54', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1032', 'pressureInches': '30', 'shortRad': '240.7', 'tempC': '-5', 'tempF': '24', 'time': '1200', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'S', 'winddirDegree': '170', 'windspeedKmph': '4', 'windspeedMiles': '2'}, {'DewPointC': '-12', 'DewPointF': '10', 'FeelsLikeC': '-3', 'FeelsLikeF': '26', 'HeatIndexC': '-3', 'HeatIndexF': '26', 'WindChillC': '-3', 'WindChillF': '26', 'WindGustKmph': '3', 'WindGustMiles': '2', 'chanceoffog': '0', 'chanceoffrost': '82', 'chanceofhightemp': '0', 'chanceofovercast': '42', 'chanceofrain': '0', 'chanceofremdry': '94', 'chanceofsnow': '0', 'chanceofsunshine': '81', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '55', 'diffRad': '95.2', 'humidity': '49', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1031', 'pressureInches': '30', 'shortRad': '360.6', 'tempC': '-3', 'tempF': '26', 'time': '1500', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'WSW', 'winddirDegree': '242', 'windspeedKmph': '3', 'windspeedMiles': '2'}, {'DewPointC': '-12', 'DewPointF': '11', 'FeelsLikeC': '-4', 'FeelsLikeF': '26', 'HeatIndexC': '-4', 'HeatIndexF': '26', 'WindChillC': '-4', 'WindChillF': '26', 'WindGustKmph': '3', 'WindGustMiles': '2', 'chanceoffog': '0', 'chanceoffrost': '81', 'chanceofhightemp': '0', 'chanceofovercast': '82', 'chanceofrain': '0', 'chanceofremdry': '86', 'chanceofsnow': '0', 'chanceofsunshine': '17', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '84', 'diffRad': '51.5', 'humidity': '53', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1033', 'pressureInches': '30', 'shortRad': '156.1', 'tempC': '-4', 'tempF': '26', 'time': '1800', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'SW', 'winddirDegree': '235', 'windspeedKmph': '2', 'windspeedMiles': '1'}, {'DewPointC': '-11', 'DewPointF': '12', 'FeelsLikeC': '-4', 'FeelsLikeF': '25', 'HeatIndexC': '-4', 'HeatIndexF': '25', 'WindChillC': '-4', 'WindChillF': '25', 'WindGustKmph': '3', 'WindGustMiles': '2', 'chanceoffog': '0', 'chanceoffrost': '81', 'chanceofhightemp': '0', 'chanceofovercast': '34', 'chanceofrain': '0', 'chanceofremdry': '92', 'chanceofsnow': '0', 'chanceofsunshine': '88', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '44', 'diffRad': '0.0', 'humidity': '58', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1034', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-4', 'tempF': '25', 'time': '2100', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'WSW', 'winddirDegree': '251', 'windspeedKmph': '2', 'windspeedMiles': '1'}], 'maxtempC': '-3', 'maxtempF': '26', 'mintempC': '-8', 'mintempF': '18', 'sunHour': '8.5', 'totalSnow_cm': '0.5', 'uvIndex': '0'}, {'astronomy': [{'moon_illumination': '0', 'moon_phase': 'Waxing Crescent', 'moonrise': '08:01 AM', 'moonset': '05:38 PM', 'sunrise': '07:33 AM', 'sunset': '05:18 PM'}], 'avgtempC': '-5', 'avgtempF': '22', 'date': '2026-01-19', 'hourly': [{'DewPointC': '-10', 'DewPointF': '14', 'FeelsLikeC': '-4', 'FeelsLikeF': '24', 'HeatIndexC': '-4', 'HeatIndexF': '24', 'WindChillC': '-4', 'WindChillF': '24', 'WindGustKmph': '2', 'WindGustMiles': '1', 'chanceoffog': '0', 'chanceoffrost': '82', 'chanceofhightemp': '0', 'chanceofovercast': '38', 'chanceofrain': '0', 'chanceofremdry': '89', 'chanceofsnow': '0', 'chanceofsunshine': '87', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '39', 'diffRad': '0.0', 'humidity': '63', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1034', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-4', 'tempF': '24', 'time': '0', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'WNW', 'winddirDegree': '282', 'windspeedKmph': '1', 'windspeedMiles': '1'}, {'DewPointC': '-11', 'DewPointF': '13', 'FeelsLikeC': '-7', 'FeelsLikeF': '20', 'HeatIndexC': '-4', 'HeatIndexF': '24', 'WindChillC': '-7', 'WindChillF': '20', 'WindGustKmph': '8', 'WindGustMiles': '5', 'chanceoffog': '0', 'chanceoffrost': '82', 'chanceofhightemp': '0', 'chanceofovercast': '87', 'chanceofrain': '0', 'chanceofremdry': '89', 'chanceofsnow': '0', 'chanceofsunshine': '10', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '76', 'diffRad': '0.0', 'humidity': '60', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1036', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-4', 'tempF': '24', 'time': '300', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNE', 'winddirDegree': '29', 'windspeedKmph': '5', 'windspeedMiles': '3'}, {'DewPointC': '-17', 'DewPointF': '2', 'FeelsLikeC': '-10', 'FeelsLikeF': '14', 'HeatIndexC': '-5', 'HeatIndexF': '22', 'WindChillC': '-10', 'WindChillF': '14', 'WindGustKmph': '16', 'WindGustMiles': '10', 'chanceoffog': '0', 'chanceoffrost': '81', 'chanceofhightemp': '0', 'chanceofovercast': '86', 'chanceofrain': '0', 'chanceofremdry': '82', 'chanceofsnow': '0', 'chanceofsunshine': '6', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '100', 'diffRad': '0.0', 'humidity': '40', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1037', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-5', 'tempF': '22', 'time': '600', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '122', 'weatherDesc': [{'value': 'Overcast '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNE', 'winddirDegree': '22', 'windspeedKmph': '11', 'windspeedMiles': '7'}, {'DewPointC': '-22', 'DewPointF': '-8', 'FeelsLikeC': '-13', 'FeelsLikeF': '9', 'HeatIndexC': '-7', 'HeatIndexF': '20', 'WindChillC': '-13', 'WindChillF': '9', 'WindGustKmph': '22', 'WindGustMiles': '13', 'chanceoffog': '0', 'chanceoffrost': '80', 'chanceofhightemp': '0', 'chanceofovercast': '45', 'chanceofrain': '0', 'chanceofremdry': '94', 'chanceofsnow': '0', 'chanceofsunshine': '73', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '47', 'diffRad': '36.8', 'humidity': '27', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1039', 'pressureInches': '31', 'shortRad': '80.4', 'tempC': '-7', 'tempF': '20', 'time': '900', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'N', 'winddirDegree': '11', 'windspeedKmph': '17', 'windspeedMiles': '10'}, {'DewPointC': '-24', 'DewPointF': '-11', 'FeelsLikeC': '-12', 'FeelsLikeF': '10', 'HeatIndexC': '-5', 'HeatIndexF': '23', 'WindChillC': '-12', 'WindChillF': '10', 'WindGustKmph': '24', 'WindGustMiles': '15', 'chanceoffog': '0', 'chanceoffrost': '80', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '92', 'chanceofsnow': '0', 'chanceofsunshine': '85', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '18', 'diffRad': '64.6', 'humidity': '21', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1039', 'pressureInches': '31', 'shortRad': '313.8', 'tempC': '-5', 'tempF': '23', 'time': '1200', 'uvIndex': '2', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Sunny'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '340', 'windspeedKmph': '21', 'windspeedMiles': '13'}, {'DewPointC': '-25', 'DewPointF': '-13', 'FeelsLikeC': '-11', 'FeelsLikeF': '12', 'HeatIndexC': '-4', 'HeatIndexF': '24', 'WindChillC': '-11', 'WindChillF': '12', 'WindGustKmph': '25', 'WindGustMiles': '16', 'chanceoffog': '0', 'chanceoffrost': '79', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '80', 'chanceofsnow': '0', 'chanceofsunshine': '92', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '7', 'diffRad': '72.6', 'humidity': '19', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1038', 'pressureInches': '31', 'shortRad': '393.0', 'tempC': '-4', 'tempF': '24', 'time': '1500', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Sunny'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NW', 'winddirDegree': '323', 'windspeedKmph': '21', 'windspeedMiles': '13'}, {'DewPointC': '-26', 'DewPointF': '-15', 'FeelsLikeC': '-12', 'FeelsLikeF': '10', 'HeatIndexC': '-5', 'HeatIndexF': '22', 'WindChillC': '-12', 'WindChillF': '10', 'WindGustKmph': '27', 'WindGustMiles': '17', 'chanceoffog': '0', 'chanceoffrost': '79', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '94', 'chanceofsnow': '0', 'chanceofsunshine': '92', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '11', 'diffRad': '45.2', 'humidity': '18', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1039', 'pressureInches': '31', 'shortRad': '171.5', 'tempC': '-5', 'tempF': '22', 'time': '1800', 'uvIndex': '0', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Clear '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '334', 'windspeedKmph': '20', 'windspeedMiles': '12'}, {'DewPointC': '-27', 'DewPointF': '-17', 'FeelsLikeC': '-13', 'FeelsLikeF': '8', 'HeatIndexC': '-7', 'HeatIndexF': '20', 'WindChillC': '-13', 'WindChillF': '8', 'WindGustKmph': '24', 'WindGustMiles': '15', 'chanceoffog': '0', 'chanceoffrost': '78', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '86', 'chanceofsnow': '0', 'chanceofsunshine': '90', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '12', 'diffRad': '15.1', 'humidity': '18', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1042', 'pressureInches': '31', 'shortRad': '57.2', 'tempC': '-7', 'tempF': '20', 'time': '2100', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Clear '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '346', 'windspeedKmph': '18', 'windspeedMiles': '11'}], 'maxtempC': '-4', 'maxtempF': '24', 'mintempC': '-8', 'mintempF': '18', 'sunHour': '9.9', 'totalSnow_cm': '0.0', 'uvIndex': '0'}, {'astronomy': [{'moon_illumination': '1', 'moon_phase': 'Waxing Crescent', 'moonrise': '08:31 AM', 'moonset': '06:45 PM', 'sunrise': '07:32 AM', 'sunset': '05:19 PM'}], 'avgtempC': '-8', 'avgtempF': '18', 'date': '2026-01-20', 'hourly': [{'DewPointC': '-27', 'DewPointF': '-17', 'FeelsLikeC': '-15', 'FeelsLikeF': '4', 'HeatIndexC': '-8', 'HeatIndexF': '17', 'WindChillC': '-15', 'WindChillF': '4', 'WindGustKmph': '26', 'WindGustMiles': '16', 'chanceoffog': '0', 'chanceoffrost': '78', 'chanceofhightemp': '0', 'chanceofovercast': '16', 'chanceofrain': '0', 'chanceofremdry': '90', 'chanceofsnow': '0', 'chanceofsunshine': '92', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '21', 'diffRad': '0.0', 'humidity': '19', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1043', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-8', 'tempF': '17', 'time': '0', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'N', 'winddirDegree': '350', 'windspeedKmph': '19', 'windspeedMiles': '12'}, {'DewPointC': '-28', 'DewPointF': '-18', 'FeelsLikeC': '-16', 'FeelsLikeF': '3', 'HeatIndexC': '-9', 'HeatIndexF': '16', 'WindChillC': '-16', 'WindChillF': '3', 'WindGustKmph': '23', 'WindGustMiles': '15', 'chanceoffog': '0', 'chanceoffrost': '77', 'chanceofhightemp': '0', 'chanceofovercast': '44', 'chanceofrain': '0', 'chanceofremdry': '90', 'chanceofsnow': '0', 'chanceofsunshine': '88', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '44', 'diffRad': '0.0', 'humidity': '20', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1043', 'pressureInches': '31', 'shortRad': '0.0', 'tempC': '-9', 'tempF': '16', 'time': '300', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '116', 'weatherDesc': [{'value': 'Partly Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'N', 'winddirDegree': '352', 'windspeedKmph': '18', 'windspeedMiles': '11'}, {'DewPointC': '-28', 'DewPointF': '-19', 'FeelsLikeC': '-17', 'FeelsLikeF': '2', 'HeatIndexC': '-10', 'HeatIndexF': '15', 'WindChillC': '-17', 'WindChillF': '2', 'WindGustKmph': '21', 'WindGustMiles': '13', 'chanceoffog': '0', 'chanceoffrost': '77', 'chanceofhightemp': '0', 'chanceofovercast': '50', 'chanceofrain': '0', 'chanceofremdry': '89', 'chanceofsnow': '0', 'chanceofsunshine': '63', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '65', 'diffRad': '0.2', 'humidity': '20', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1043', 'pressureInches': '31', 'shortRad': '0.5', 'tempC': '-10', 'tempF': '15', 'time': '600', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '122', 'weatherDesc': [{'value': 'Overcast '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'N', 'winddirDegree': '350', 'windspeedKmph': '16', 'windspeedMiles': '10'}, {'DewPointC': '-29', 'DewPointF': '-19', 'FeelsLikeC': '-16', 'FeelsLikeF': '3', 'HeatIndexC': '-9', 'HeatIndexF': '15', 'WindChillC': '-16', 'WindChillF': '3', 'WindGustKmph': '20', 'WindGustMiles': '13', 'chanceoffog': '0', 'chanceoffrost': '76', 'chanceofhightemp': '0', 'chanceofovercast': '82', 'chanceofrain': '0', 'chanceofremdry': '86', 'chanceofsnow': '0', 'chanceofsunshine': '16', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '88', 'diffRad': '43.7', 'humidity': '19', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1043', 'pressureInches': '31', 'shortRad': '113.2', 'tempC': '-9', 'tempF': '15', 'time': '900', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '347', 'windspeedKmph': '15', 'windspeedMiles': '10'}, {'DewPointC': '-29', 'DewPointF': '-20', 'FeelsLikeC': '-14', 'FeelsLikeF': '7', 'HeatIndexC': '-7', 'HeatIndexF': '19', 'WindChillC': '-14', 'WindChillF': '7', 'WindGustKmph': '21', 'WindGustMiles': '13', 'chanceoffog': '0', 'chanceoffrost': '76', 'chanceofhightemp': '0', 'chanceofovercast': '57', 'chanceofrain': '0', 'chanceofremdry': '85', 'chanceofsnow': '0', 'chanceofsunshine': '36', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '44', 'diffRad': '85.2', 'humidity': '16', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1042', 'pressureInches': '31', 'shortRad': '297.8', 'tempC': '-7', 'tempF': '19', 'time': '1200', 'uvIndex': '2', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Sunny'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '338', 'windspeedKmph': '18', 'windspeedMiles': '11'}, {'DewPointC': '-29', 'DewPointF': '-20', 'FeelsLikeC': '-12', 'FeelsLikeF': '10', 'HeatIndexC': '-6', 'HeatIndexF': '22', 'WindChillC': '-12', 'WindChillF': '10', 'WindGustKmph': '22', 'WindGustMiles': '14', 'chanceoffog': '0', 'chanceoffrost': '67', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '90', 'chanceofsnow': '0', 'chanceofsunshine': '88', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '0', 'diffRad': '67.4', 'humidity': '14', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1040', 'pressureInches': '31', 'shortRad': '312.4', 'tempC': '-6', 'tempF': '22', 'time': '1500', 'uvIndex': '2', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Sunny'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NNW', 'winddirDegree': '328', 'windspeedKmph': '18', 'windspeedMiles': '11'}, {'DewPointC': '-28', 'DewPointF': '-18', 'FeelsLikeC': '-12', 'FeelsLikeF': '11', 'HeatIndexC': '-6', 'HeatIndexF': '22', 'WindChillC': '-12', 'WindChillF': '11', 'WindGustKmph': '22', 'WindGustMiles': '14', 'chanceoffog': '0', 'chanceoffrost': '50', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '86', 'chanceofsnow': '0', 'chanceofsunshine': '87', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '0', 'diffRad': '38.5', 'humidity': '16', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1039', 'pressureInches': '31', 'shortRad': '191.1', 'tempC': '-6', 'tempF': '22', 'time': '1800', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Clear '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NW', 'winddirDegree': '319', 'windspeedKmph': '15', 'windspeedMiles': '9'}, {'DewPointC': '-27', 'DewPointF': '-17', 'FeelsLikeC': '-12', 'FeelsLikeF': '10', 'HeatIndexC': '-7', 'HeatIndexF': '20', 'WindChillC': '-12', 'WindChillF': '10', 'WindGustKmph': '20', 'WindGustMiles': '13', 'chanceoffog': '0', 'chanceoffrost': '50', 'chanceofhightemp': '0', 'chanceofovercast': '0', 'chanceofrain': '0', 'chanceofremdry': '87', 'chanceofsnow': '0', 'chanceofsunshine': '90', 'chanceofthunder': '0', 'chanceofwindy': '0', 'cloudcover': '0', 'diffRad': '12.9', 'humidity': '18', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1039', 'pressureInches': '31', 'shortRad': '63.8', 'tempC': '-7', 'tempF': '20', 'time': '2100', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '113', 'weatherDesc': [{'value': 'Clear '}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'NW', 'winddirDegree': '318', 'windspeedKmph': '13', 'windspeedMiles': '8'}], 'maxtempC': '-6', 'maxtempF': '22', 'mintempC': '-10', 'mintempF': '14', 'sunHour': '8.3', 'totalSnow_cm': '0.0', 'uvIndex': '2'}]}
复制代码
       使用python自带的pprint(Pretty Print)库,结构就会十分的清晰:
  1. {'current_condition': [{'FeelsLikeC': '-5',
  2.                         'FeelsLikeF': '24',
  3.                         'cloudcover': '0',
  4.                         'humidity': '54',
  5.                         'localObsDateTime': '2026-01-18 02:36 PM',
  6.                         'observation_time': '06:36 AM',
  7.                         'precipInches': '0.0',
  8.                         'precipMM': '0.0',
  9.                         'pressure': '1029',
  10.                         'pressureInches': '30',
  11.                         'temp_C': '-3',
  12.                         'temp_F': '27',
  13.                         'uvIndex': '1',
  14.                         'visibility': '10',
  15.                         'visibilityMiles': '6',
  16.                         'weatherCode': '116',
  17.                         'weatherDesc': [{'value': 'Partly cloudy'}],
  18.                         'weatherIconUrl': [{'value': ''}],
  19.                         'winddir16Point': 'SSE',
  20.                         'winddirDegree': '163',
  21.                         'windspeedKmph': '5',
  22.                         'windspeedMiles': '3'}],
  23. 'nearest_area': [{'areaName': [{'value': 'Beijing'}],
  24.                    'country': [{'value': 'China'}],
  25.                    'latitude': '39.929',
  26.                    'longitude': '116.388',
  27.                    'population': '7480601',
  28.                    'region': [{'value': 'Beijing'}],
  29.                    'weatherUrl': [{'value': ''}]}],
  30. 'request': [{'query': 'Lat 39.91 and Lon 116.39', 'type': 'LatLon'}],
  31. 'weather': [{'astronomy': [{'moon_illumination': '1',
  32.                              'moon_phase': 'New Moon',
  33.                              'moonrise': '07:24 AM',
  34.                              'moonset': '04:31 PM',
  35.                              'sunrise': '07:33 AM',
  36.                              'sunset': '05:17 PM'}],
  37.               'avgtempC': '-5',
  38.               'avgtempF': '22',
  39.               'date': '2026-01-18',
  40.               'hourly': [{'DewPointC': '-12',
  41.                           'DewPointF': '11',
  42.                           'FeelsLikeC': '-11',
  43.                           'FeelsLikeF': '13',
  44.                           'HeatIndexC': '-7',
  45.                           'HeatIndexF': '20',
  46.                           'WindChillC': '-11',
  47.                           'WindChillF': '13',
  48.                           'WindGustKmph': '11',
  49.                           'WindGustMiles': '7',
  50.                           'chanceoffog': '0',
  51.                           'chanceoffrost': '86',
  52.                           'chanceofhightemp': '0',
  53.                           'chanceofovercast': '90',
  54.                           'chanceofrain': '100',
  55.                           'chanceofremdry': '0',
  56.                           'chanceofsnow': '63',
  57.                           'chanceofsunshine': '0',
  58.                           'chanceofthunder': '0',
  59.                           'chanceofwindy': '0',
  60.                           'cloudcover': '100',
  61.                           'diffRad': '0.0',
  62.                           'humidity': '68',
  63.                           'precipInches': '0.0',
  64.                           'precipMM': '0.1',
  65.                           'pressure': '1030',
  66.                           'pressureInches': '30',
  67.                           'shortRad': '0.0',
  68.                           'tempC': '-7',
  69.                           'tempF': '20',
  70.                           'time': '0',
  71.                           'uvIndex': '0',
  72.                           'visibility': '10',
  73.                           'visibilityMiles': '6',
  74.                           'weatherCode': '326',
  75.                           'weatherDesc': [{'value': 'Light snow'}],
  76.                           'weatherIconUrl': [{'value': ''}],
  77.                           'winddir16Point': 'E',
  78.                           'winddirDegree': '97',
  79.                           'windspeedKmph': '9',
  80.                           'windspeedMiles': '5'},
  81.                          {'DewPointC': '-10',
  82.                           'DewPointF': '14',
  83.                           'FeelsLikeC': '-11',
  84.                           'FeelsLikeF': '12',
  85.                           'HeatIndexC': '-7',
  86.                           'HeatIndexF': '19',
  87.                           'WindChillC': '-11',
  88.                           'WindChillF': '12',
  89.                           'WindGustKmph': '9',
  90.                           'WindGustMiles': '6',
  91.                           'chanceoffog': '0',
  92.                           'chanceoffrost': '86',
  93.                           'chanceofhightemp': '0',
  94.                           'chanceofovercast': '93',
  95.                           'chanceofrain': '100',
  96.                           'chanceofremdry': '0',
  97.                           'chanceofsnow': '72',
  98.                           'chanceofsunshine': '0',
  99.                           'chanceofthunder': '0',
  100.                           'chanceofwindy': '0',
  101.                           'cloudcover': '100',
  102.                           'diffRad': '0.0',
  103.                           'humidity': '80',
  104.                           'precipInches': '0.0',
  105.                           'precipMM': '0.1',
  106.                           'pressure': '1031',
  107.                           'pressureInches': '30',
  108.                           'shortRad': '0.0',
  109.                           'tempC': '-7',
  110.                           'tempF': '19',
  111.                           'time': '300',
  112.                           'uvIndex': '0',
  113.                           'visibility': '5',
  114.                           'visibilityMiles': '3',
  115.                           'weatherCode': '332',
  116.                           'weatherDesc': [{'value': 'Moderate snow'}],
  117.                           'weatherIconUrl': [{'value': ''}],
  118.                           'winddir16Point': 'E',
  119.                           'winddirDegree': '88',
  120.                           'windspeedKmph': '7',
  121.                           'windspeedMiles': '4'},
  122.                          {'DewPointC': '-10',
  123.                           'DewPointF': '13',
  124.                           'FeelsLikeC': '-11',
  125.                           'FeelsLikeF': '12',
  126.                           'HeatIndexC': '-8',
  127.                           'HeatIndexF': '18',
  128.                           'WindChillC': '-11',
  129.                           'WindChillF': '12',
  130.                           'WindGustKmph': '9',
  131.                           'WindGustMiles': '5',
  132.                           'chanceoffog': '0',
  133.                           'chanceoffrost': '85',
  134.                           'chanceofhightemp': '0',
  135.                           'chanceofovercast': '90',
  136.                           'chanceofrain': '100',
  137.                           'chanceofremdry': '0',
  138.                           'chanceofsnow': '66',
  139.                           'chanceofsunshine': '0',
  140.                           'chanceofthunder': '0',
  141.                           'chanceofwindy': '0',
  142.                           'cloudcover': '100',
  143.                           'diffRad': '0.0',
  144.                           'humidity': '81',
  145.                           'precipInches': '0.0',
  146.                           'precipMM': '0.1',
  147.                           'pressure': '1031',
  148.                           'pressureInches': '30',
  149.                           'shortRad': '0.0',
  150.                           'tempC': '-8',
  151.                           'tempF': '18',
  152.                           'time': '600',
  153.                           'uvIndex': '0',
  154.                           'visibility': '5',
  155.                           'visibilityMiles': '3',
  156.                           'weatherCode': '332',
  157.                           'weatherDesc': [{'value': 'Moderate snow'}],
  158.                           'weatherIconUrl': [{'value': ''}],
  159.                           'winddir16Point': 'E',
  160.                           'winddirDegree': '88',
  161.                           'windspeedKmph': '6',
  162.                           'windspeedMiles': '4'},
  163.                          {'DewPointC': '-12',
  164.                           'DewPointF': '10',
  165.                           'FeelsLikeC': '-9',
  166.                           'FeelsLikeF': '16',
  167.                           'HeatIndexC': '-7',
  168.                           'HeatIndexF': '19',
  169.                           'WindChillC': '-9',
  170.                           'WindChillF': '16',
  171.                           'WindGustKmph': '5',
  172.                           'WindGustMiles': '3',
  173.                           'chanceoffog': '0',
  174.                           'chanceoffrost': '85',
  175.                           'chanceofhightemp': '0',
  176.                           'chanceofovercast': '83',
  177.                           'chanceofrain': '0',
  178.                           'chanceofremdry': '0',
  179.                           'chanceofsnow': '82',
  180.                           'chanceofsunshine': '0',
  181.                           'chanceofthunder': '0',
  182.                           'chanceofwindy': '0',
  183.                           'cloudcover': '100',
  184.                           'diffRad': '29.8',
  185.                           'humidity': '68',
  186.                           'precipInches': '0.0',
  187.                           'precipMM': '0.0',
  188.                           'pressure': '1033',
  189.                           'pressureInches': '31',
  190.                           'shortRad': '62.0',
  191.                           'tempC': '-7',
  192.                           'tempF': '19',
  193.                           'time': '900',
  194.                           'uvIndex': '0',
  195.                           'visibility': '10',
  196.                           'visibilityMiles': '6',
  197.                           'weatherCode': '311',
  198.                           'weatherDesc': [{'value': 'Light freezing rain'}],
  199.                           'weatherIconUrl': [{'value': ''}],
  200.                           'winddir16Point': 'ESE',
  201.                           'winddirDegree': '119',
  202.                           'windspeedKmph': '4',
  203.                           'windspeedMiles': '2'},
  204.                          {'DewPointC': '-12',
  205.                           'DewPointF': '10',
  206.                           'FeelsLikeC': '-6',
  207.                           'FeelsLikeF': '21',
  208.                           'HeatIndexC': '-5',
  209.                           'HeatIndexF': '24',
  210.                           'WindChillC': '-6',
  211.                           'WindChillF': '21',
  212.                           'WindGustKmph': '4',
  213.                           'WindGustMiles': '3',
  214.                           'chanceoffog': '0',
  215.                           'chanceoffrost': '84',
  216.                           'chanceofhightemp': '0',
  217.                           'chanceofovercast': '94',
  218.                           'chanceofrain': '0',
  219.                           'chanceofremdry': '85',
  220.                           'chanceofsnow': '0',
  221.                           'chanceofsunshine': '16',
  222.                           'chanceofthunder': '0',
  223.                           'chanceofwindy': '0',
  224.                           'cloudcover': '82',
  225.                           'diffRad': '97.3',
  226.                           'humidity': '54',
  227.                           'precipInches': '0.0',
  228.                           'precipMM': '0.0',
  229.                           'pressure': '1032',
  230.                           'pressureInches': '30',
  231.                           'shortRad': '240.7',
  232.                           'tempC': '-5',
  233.                           'tempF': '24',
  234.                           'time': '1200',
  235.                           'uvIndex': '1',
  236.                           'visibility': '10',
  237.                           'visibilityMiles': '6',
  238.                           'weatherCode': '119',
  239.                           'weatherDesc': [{'value': 'Cloudy '}],
  240.                           'weatherIconUrl': [{'value': ''}],
  241.                           'winddir16Point': 'S',
  242.                           'winddirDegree': '170',
  243.                           'windspeedKmph': '4',
  244.                           'windspeedMiles': '2'},
  245.                          {'DewPointC': '-12',
  246.                           'DewPointF': '10',
  247.                           'FeelsLikeC': '-3',
  248.                           'FeelsLikeF': '26',
  249.                           'HeatIndexC': '-3',
  250.                           'HeatIndexF': '26',
  251.                           'WindChillC': '-3',
  252.                           'WindChillF': '26',
  253.                           'WindGustKmph': '3',
  254.                           'WindGustMiles': '2',
  255.                           'chanceoffog': '0',
  256.                           'chanceoffrost': '82',
  257.                           'chanceofhightemp': '0',
  258.                           'chanceofovercast': '42',
  259.                           'chanceofrain': '0',
  260.                           'chanceofremdry': '94',
  261.                           'chanceofsnow': '0',
  262.                           'chanceofsunshine': '81',
  263.                           'chanceofthunder': '0',
  264.                           'chanceofwindy': '0',
  265.                           'cloudcover': '55',
  266.                           'diffRad': '95.2',
  267.                           'humidity': '49',
  268.                           'precipInches': '0.0',
  269.                           'precipMM': '0.0',
  270.                           'pressure': '1031',
  271.                           'pressureInches': '30',
  272.                           'shortRad': '360.6',
  273.                           'tempC': '-3',
  274.                           'tempF': '26',
  275.                           'time': '1500',
  276.                           'uvIndex': '0',
  277.                           'visibility': '10',
  278.                           'visibilityMiles': '6',
  279.                           'weatherCode': '116',
  280.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  281.                           'weatherIconUrl': [{'value': ''}],
  282.                           'winddir16Point': 'WSW',
  283.                           'winddirDegree': '242',
  284.                           'windspeedKmph': '3',
  285.                           'windspeedMiles': '2'},
  286.                          {'DewPointC': '-12',
  287.                           'DewPointF': '11',
  288.                           'FeelsLikeC': '-4',
  289.                           'FeelsLikeF': '26',
  290.                           'HeatIndexC': '-4',
  291.                           'HeatIndexF': '26',
  292.                           'WindChillC': '-4',
  293.                           'WindChillF': '26',
  294.                           'WindGustKmph': '3',
  295.                           'WindGustMiles': '2',
  296.                           'chanceoffog': '0',
  297.                           'chanceoffrost': '81',
  298.                           'chanceofhightemp': '0',
  299.                           'chanceofovercast': '82',
  300.                           'chanceofrain': '0',
  301.                           'chanceofremdry': '86',
  302.                           'chanceofsnow': '0',
  303.                           'chanceofsunshine': '17',
  304.                           'chanceofthunder': '0',
  305.                           'chanceofwindy': '0',
  306.                           'cloudcover': '84',
  307.                           'diffRad': '51.5',
  308.                           'humidity': '53',
  309.                           'precipInches': '0.0',
  310.                           'precipMM': '0.0',
  311.                           'pressure': '1033',
  312.                           'pressureInches': '30',
  313.                           'shortRad': '156.1',
  314.                           'tempC': '-4',
  315.                           'tempF': '26',
  316.                           'time': '1800',
  317.                           'uvIndex': '0',
  318.                           'visibility': '10',
  319.                           'visibilityMiles': '6',
  320.                           'weatherCode': '119',
  321.                           'weatherDesc': [{'value': 'Cloudy '}],
  322.                           'weatherIconUrl': [{'value': ''}],
  323.                           'winddir16Point': 'SW',
  324.                           'winddirDegree': '235',
  325.                           'windspeedKmph': '2',
  326.                           'windspeedMiles': '1'},
  327.                          {'DewPointC': '-11',
  328.                           'DewPointF': '12',
  329.                           'FeelsLikeC': '-4',
  330.                           'FeelsLikeF': '25',
  331.                           'HeatIndexC': '-4',
  332.                           'HeatIndexF': '25',
  333.                           'WindChillC': '-4',
  334.                           'WindChillF': '25',
  335.                           'WindGustKmph': '3',
  336.                           'WindGustMiles': '2',
  337.                           'chanceoffog': '0',
  338.                           'chanceoffrost': '81',
  339.                           'chanceofhightemp': '0',
  340.                           'chanceofovercast': '34',
  341.                           'chanceofrain': '0',
  342.                           'chanceofremdry': '92',
  343.                           'chanceofsnow': '0',
  344.                           'chanceofsunshine': '88',
  345.                           'chanceofthunder': '0',
  346.                           'chanceofwindy': '0',
  347.                           'cloudcover': '44',
  348.                           'diffRad': '0.0',
  349.                           'humidity': '58',
  350.                           'precipInches': '0.0',
  351.                           'precipMM': '0.0',
  352.                           'pressure': '1034',
  353.                           'pressureInches': '31',
  354.                           'shortRad': '0.0',
  355.                           'tempC': '-4',
  356.                           'tempF': '25',
  357.                           'time': '2100',
  358.                           'uvIndex': '0',
  359.                           'visibility': '10',
  360.                           'visibilityMiles': '6',
  361.                           'weatherCode': '116',
  362.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  363.                           'weatherIconUrl': [{'value': ''}],
  364.                           'winddir16Point': 'WSW',
  365.                           'winddirDegree': '251',
  366.                           'windspeedKmph': '2',
  367.                           'windspeedMiles': '1'}],
  368.               'maxtempC': '-3',
  369.               'maxtempF': '26',
  370.               'mintempC': '-8',
  371.               'mintempF': '18',
  372.               'sunHour': '8.5',
  373.               'totalSnow_cm': '0.5',
  374.               'uvIndex': '0'},
  375.              {'astronomy': [{'moon_illumination': '0',
  376.                              'moon_phase': 'Waxing Crescent',
  377.                              'moonrise': '08:01 AM',
  378.                              'moonset': '05:38 PM',
  379.                              'sunrise': '07:33 AM',
  380.                              'sunset': '05:18 PM'}],
  381.               'avgtempC': '-5',
  382.               'avgtempF': '22',
  383.               'date': '2026-01-19',
  384.               'hourly': [{'DewPointC': '-10',
  385.                           'DewPointF': '14',
  386.                           'FeelsLikeC': '-4',
  387.                           'FeelsLikeF': '24',
  388.                           'HeatIndexC': '-4',
  389.                           'HeatIndexF': '24',
  390.                           'WindChillC': '-4',
  391.                           'WindChillF': '24',
  392.                           'WindGustKmph': '2',
  393.                           'WindGustMiles': '1',
  394.                           'chanceoffog': '0',
  395.                           'chanceoffrost': '82',
  396.                           'chanceofhightemp': '0',
  397.                           'chanceofovercast': '38',
  398.                           'chanceofrain': '0',
  399.                           'chanceofremdry': '89',
  400.                           'chanceofsnow': '0',
  401.                           'chanceofsunshine': '87',
  402.                           'chanceofthunder': '0',
  403.                           'chanceofwindy': '0',
  404.                           'cloudcover': '39',
  405.                           'diffRad': '0.0',
  406.                           'humidity': '63',
  407.                           'precipInches': '0.0',
  408.                           'precipMM': '0.0',
  409.                           'pressure': '1034',
  410.                           'pressureInches': '31',
  411.                           'shortRad': '0.0',
  412.                           'tempC': '-4',
  413.                           'tempF': '24',
  414.                           'time': '0',
  415.                           'uvIndex': '0',
  416.                           'visibility': '10',
  417.                           'visibilityMiles': '6',
  418.                           'weatherCode': '116',
  419.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  420.                           'weatherIconUrl': [{'value': ''}],
  421.                           'winddir16Point': 'WNW',
  422.                           'winddirDegree': '282',
  423.                           'windspeedKmph': '1',
  424.                           'windspeedMiles': '1'},
  425.                          {'DewPointC': '-11',
  426.                           'DewPointF': '13',
  427.                           'FeelsLikeC': '-7',
  428.                           'FeelsLikeF': '20',
  429.                           'HeatIndexC': '-4',
  430.                           'HeatIndexF': '24',
  431.                           'WindChillC': '-7',
  432.                           'WindChillF': '20',
  433.                           'WindGustKmph': '8',
  434.                           'WindGustMiles': '5',
  435.                           'chanceoffog': '0',
  436.                           'chanceoffrost': '82',
  437.                           'chanceofhightemp': '0',
  438.                           'chanceofovercast': '87',
  439.                           'chanceofrain': '0',
  440.                           'chanceofremdry': '89',
  441.                           'chanceofsnow': '0',
  442.                           'chanceofsunshine': '10',
  443.                           'chanceofthunder': '0',
  444.                           'chanceofwindy': '0',
  445.                           'cloudcover': '76',
  446.                           'diffRad': '0.0',
  447.                           'humidity': '60',
  448.                           'precipInches': '0.0',
  449.                           'precipMM': '0.0',
  450.                           'pressure': '1036',
  451.                           'pressureInches': '31',
  452.                           'shortRad': '0.0',
  453.                           'tempC': '-4',
  454.                           'tempF': '24',
  455.                           'time': '300',
  456.                           'uvIndex': '0',
  457.                           'visibility': '10',
  458.                           'visibilityMiles': '6',
  459.                           'weatherCode': '119',
  460.                           'weatherDesc': [{'value': 'Cloudy '}],
  461.                           'weatherIconUrl': [{'value': ''}],
  462.                           'winddir16Point': 'NNE',
  463.                           'winddirDegree': '29',
  464.                           'windspeedKmph': '5',
  465.                           'windspeedMiles': '3'},
  466.                          {'DewPointC': '-17',
  467.                           'DewPointF': '2',
  468.                           'FeelsLikeC': '-10',
  469.                           'FeelsLikeF': '14',
  470.                           'HeatIndexC': '-5',
  471.                           'HeatIndexF': '22',
  472.                           'WindChillC': '-10',
  473.                           'WindChillF': '14',
  474.                           'WindGustKmph': '16',
  475.                           'WindGustMiles': '10',
  476.                           'chanceoffog': '0',
  477.                           'chanceoffrost': '81',
  478.                           'chanceofhightemp': '0',
  479.                           'chanceofovercast': '86',
  480.                           'chanceofrain': '0',
  481.                           'chanceofremdry': '82',
  482.                           'chanceofsnow': '0',
  483.                           'chanceofsunshine': '6',
  484.                           'chanceofthunder': '0',
  485.                           'chanceofwindy': '0',
  486.                           'cloudcover': '100',
  487.                           'diffRad': '0.0',
  488.                           'humidity': '40',
  489.                           'precipInches': '0.0',
  490.                           'precipMM': '0.0',
  491.                           'pressure': '1037',
  492.                           'pressureInches': '31',
  493.                           'shortRad': '0.0',
  494.                           'tempC': '-5',
  495.                           'tempF': '22',
  496.                           'time': '600',
  497.                           'uvIndex': '0',
  498.                           'visibility': '10',
  499.                           'visibilityMiles': '6',
  500.                           'weatherCode': '122',
  501.                           'weatherDesc': [{'value': 'Overcast '}],
  502.                           'weatherIconUrl': [{'value': ''}],
  503.                           'winddir16Point': 'NNE',
  504.                           'winddirDegree': '22',
  505.                           'windspeedKmph': '11',
  506.                           'windspeedMiles': '7'},
  507.                          {'DewPointC': '-22',
  508.                           'DewPointF': '-8',
  509.                           'FeelsLikeC': '-13',
  510.                           'FeelsLikeF': '9',
  511.                           'HeatIndexC': '-7',
  512.                           'HeatIndexF': '20',
  513.                           'WindChillC': '-13',
  514.                           'WindChillF': '9',
  515.                           'WindGustKmph': '22',
  516.                           'WindGustMiles': '13',
  517.                           'chanceoffog': '0',
  518.                           'chanceoffrost': '80',
  519.                           'chanceofhightemp': '0',
  520.                           'chanceofovercast': '45',
  521.                           'chanceofrain': '0',
  522.                           'chanceofremdry': '94',
  523.                           'chanceofsnow': '0',
  524.                           'chanceofsunshine': '73',
  525.                           'chanceofthunder': '0',
  526.                           'chanceofwindy': '0',
  527.                           'cloudcover': '47',
  528.                           'diffRad': '36.8',
  529.                           'humidity': '27',
  530.                           'precipInches': '0.0',
  531.                           'precipMM': '0.0',
  532.                           'pressure': '1039',
  533.                           'pressureInches': '31',
  534.                           'shortRad': '80.4',
  535.                           'tempC': '-7',
  536.                           'tempF': '20',
  537.                           'time': '900',
  538.                           'uvIndex': '0',
  539.                           'visibility': '10',
  540.                           'visibilityMiles': '6',
  541.                           'weatherCode': '116',
  542.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  543.                           'weatherIconUrl': [{'value': ''}],
  544.                           'winddir16Point': 'N',
  545.                           'winddirDegree': '11',
  546.                           'windspeedKmph': '17',
  547.                           'windspeedMiles': '10'},
  548.                          {'DewPointC': '-24',
  549.                           'DewPointF': '-11',
  550.                           'FeelsLikeC': '-12',
  551.                           'FeelsLikeF': '10',
  552.                           'HeatIndexC': '-5',
  553.                           'HeatIndexF': '23',
  554.                           'WindChillC': '-12',
  555.                           'WindChillF': '10',
  556.                           'WindGustKmph': '24',
  557.                           'WindGustMiles': '15',
  558.                           'chanceoffog': '0',
  559.                           'chanceoffrost': '80',
  560.                           'chanceofhightemp': '0',
  561.                           'chanceofovercast': '0',
  562.                           'chanceofrain': '0',
  563.                           'chanceofremdry': '92',
  564.                           'chanceofsnow': '0',
  565.                           'chanceofsunshine': '85',
  566.                           'chanceofthunder': '0',
  567.                           'chanceofwindy': '0',
  568.                           'cloudcover': '18',
  569.                           'diffRad': '64.6',
  570.                           'humidity': '21',
  571.                           'precipInches': '0.0',
  572.                           'precipMM': '0.0',
  573.                           'pressure': '1039',
  574.                           'pressureInches': '31',
  575.                           'shortRad': '313.8',
  576.                           'tempC': '-5',
  577.                           'tempF': '23',
  578.                           'time': '1200',
  579.                           'uvIndex': '2',
  580.                           'visibility': '10',
  581.                           'visibilityMiles': '6',
  582.                           'weatherCode': '113',
  583.                           'weatherDesc': [{'value': 'Sunny'}],
  584.                           'weatherIconUrl': [{'value': ''}],
  585.                           'winddir16Point': 'NNW',
  586.                           'winddirDegree': '340',
  587.                           'windspeedKmph': '21',
  588.                           'windspeedMiles': '13'},
  589.                          {'DewPointC': '-25',
  590.                           'DewPointF': '-13',
  591.                           'FeelsLikeC': '-11',
  592.                           'FeelsLikeF': '12',
  593.                           'HeatIndexC': '-4',
  594.                           'HeatIndexF': '24',
  595.                           'WindChillC': '-11',
  596.                           'WindChillF': '12',
  597.                           'WindGustKmph': '25',
  598.                           'WindGustMiles': '16',
  599.                           'chanceoffog': '0',
  600.                           'chanceoffrost': '79',
  601.                           'chanceofhightemp': '0',
  602.                           'chanceofovercast': '0',
  603.                           'chanceofrain': '0',
  604.                           'chanceofremdry': '80',
  605.                           'chanceofsnow': '0',
  606.                           'chanceofsunshine': '92',
  607.                           'chanceofthunder': '0',
  608.                           'chanceofwindy': '0',
  609.                           'cloudcover': '7',
  610.                           'diffRad': '72.6',
  611.                           'humidity': '19',
  612.                           'precipInches': '0.0',
  613.                           'precipMM': '0.0',
  614.                           'pressure': '1038',
  615.                           'pressureInches': '31',
  616.                           'shortRad': '393.0',
  617.                           'tempC': '-4',
  618.                           'tempF': '24',
  619.                           'time': '1500',
  620.                           'uvIndex': '1',
  621.                           'visibility': '10',
  622.                           'visibilityMiles': '6',
  623.                           'weatherCode': '113',
  624.                           'weatherDesc': [{'value': 'Sunny'}],
  625.                           'weatherIconUrl': [{'value': ''}],
  626.                           'winddir16Point': 'NW',
  627.                           'winddirDegree': '323',
  628.                           'windspeedKmph': '21',
  629.                           'windspeedMiles': '13'},
  630.                          {'DewPointC': '-26',
  631.                           'DewPointF': '-15',
  632.                           'FeelsLikeC': '-12',
  633.                           'FeelsLikeF': '10',
  634.                           'HeatIndexC': '-5',
  635.                           'HeatIndexF': '22',
  636.                           'WindChillC': '-12',
  637.                           'WindChillF': '10',
  638.                           'WindGustKmph': '27',
  639.                           'WindGustMiles': '17',
  640.                           'chanceoffog': '0',
  641.                           'chanceoffrost': '79',
  642.                           'chanceofhightemp': '0',
  643.                           'chanceofovercast': '0',
  644.                           'chanceofrain': '0',
  645.                           'chanceofremdry': '94',
  646.                           'chanceofsnow': '0',
  647.                           'chanceofsunshine': '92',
  648.                           'chanceofthunder': '0',
  649.                           'chanceofwindy': '0',
  650.                           'cloudcover': '11',
  651.                           'diffRad': '45.2',
  652.                           'humidity': '18',
  653.                           'precipInches': '0.0',
  654.                           'precipMM': '0.0',
  655.                           'pressure': '1039',
  656.                           'pressureInches': '31',
  657.                           'shortRad': '171.5',
  658.                           'tempC': '-5',
  659.                           'tempF': '22',
  660.                           'time': '1800',
  661.                           'uvIndex': '0',
  662.                           'visibility': '10',
  663.                           'visibilityMiles': '6',
  664.                           'weatherCode': '113',
  665.                           'weatherDesc': [{'value': 'Clear '}],
  666.                           'weatherIconUrl': [{'value': ''}],
  667.                           'winddir16Point': 'NNW',
  668.                           'winddirDegree': '334',
  669.                           'windspeedKmph': '20',
  670.                           'windspeedMiles': '12'},
  671.                          {'DewPointC': '-27',
  672.                           'DewPointF': '-17',
  673.                           'FeelsLikeC': '-13',
  674.                           'FeelsLikeF': '8',
  675.                           'HeatIndexC': '-7',
  676.                           'HeatIndexF': '20',
  677.                           'WindChillC': '-13',
  678.                           'WindChillF': '8',
  679.                           'WindGustKmph': '24',
  680.                           'WindGustMiles': '15',
  681.                           'chanceoffog': '0',
  682.                           'chanceoffrost': '78',
  683.                           'chanceofhightemp': '0',
  684.                           'chanceofovercast': '0',
  685.                           'chanceofrain': '0',
  686.                           'chanceofremdry': '86',
  687.                           'chanceofsnow': '0',
  688.                           'chanceofsunshine': '90',
  689.                           'chanceofthunder': '0',
  690.                           'chanceofwindy': '0',
  691.                           'cloudcover': '12',
  692.                           'diffRad': '15.1',
  693.                           'humidity': '18',
  694.                           'precipInches': '0.0',
  695.                           'precipMM': '0.0',
  696.                           'pressure': '1042',
  697.                           'pressureInches': '31',
  698.                           'shortRad': '57.2',
  699.                           'tempC': '-7',
  700.                           'tempF': '20',
  701.                           'time': '2100',
  702.                           'uvIndex': '1',
  703.                           'visibility': '10',
  704.                           'visibilityMiles': '6',
  705.                           'weatherCode': '113',
  706.                           'weatherDesc': [{'value': 'Clear '}],
  707.                           'weatherIconUrl': [{'value': ''}],
  708.                           'winddir16Point': 'NNW',
  709.                           'winddirDegree': '346',
  710.                           'windspeedKmph': '18',
  711.                           'windspeedMiles': '11'}],
  712.               'maxtempC': '-4',
  713.               'maxtempF': '24',
  714.               'mintempC': '-8',
  715.               'mintempF': '18',
  716.               'sunHour': '9.9',
  717.               'totalSnow_cm': '0.0',
  718.               'uvIndex': '0'},
  719.              {'astronomy': [{'moon_illumination': '1',
  720.                              'moon_phase': 'Waxing Crescent',
  721.                              'moonrise': '08:31 AM',
  722.                              'moonset': '06:45 PM',
  723.                              'sunrise': '07:32 AM',
  724.                              'sunset': '05:19 PM'}],
  725.               'avgtempC': '-8',
  726.               'avgtempF': '18',
  727.               'date': '2026-01-20',
  728.               'hourly': [{'DewPointC': '-27',
  729.                           'DewPointF': '-17',
  730.                           'FeelsLikeC': '-15',
  731.                           'FeelsLikeF': '4',
  732.                           'HeatIndexC': '-8',
  733.                           'HeatIndexF': '17',
  734.                           'WindChillC': '-15',
  735.                           'WindChillF': '4',
  736.                           'WindGustKmph': '26',
  737.                           'WindGustMiles': '16',
  738.                           'chanceoffog': '0',
  739.                           'chanceoffrost': '78',
  740.                           'chanceofhightemp': '0',
  741.                           'chanceofovercast': '16',
  742.                           'chanceofrain': '0',
  743.                           'chanceofremdry': '90',
  744.                           'chanceofsnow': '0',
  745.                           'chanceofsunshine': '92',
  746.                           'chanceofthunder': '0',
  747.                           'chanceofwindy': '0',
  748.                           'cloudcover': '21',
  749.                           'diffRad': '0.0',
  750.                           'humidity': '19',
  751.                           'precipInches': '0.0',
  752.                           'precipMM': '0.0',
  753.                           'pressure': '1043',
  754.                           'pressureInches': '31',
  755.                           'shortRad': '0.0',
  756.                           'tempC': '-8',
  757.                           'tempF': '17',
  758.                           'time': '0',
  759.                           'uvIndex': '1',
  760.                           'visibility': '10',
  761.                           'visibilityMiles': '6',
  762.                           'weatherCode': '116',
  763.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  764.                           'weatherIconUrl': [{'value': ''}],
  765.                           'winddir16Point': 'N',
  766.                           'winddirDegree': '350',
  767.                           'windspeedKmph': '19',
  768.                           'windspeedMiles': '12'},
  769.                          {'DewPointC': '-28',
  770.                           'DewPointF': '-18',
  771.                           'FeelsLikeC': '-16',
  772.                           'FeelsLikeF': '3',
  773.                           'HeatIndexC': '-9',
  774.                           'HeatIndexF': '16',
  775.                           'WindChillC': '-16',
  776.                           'WindChillF': '3',
  777.                           'WindGustKmph': '23',
  778.                           'WindGustMiles': '15',
  779.                           'chanceoffog': '0',
  780.                           'chanceoffrost': '77',
  781.                           'chanceofhightemp': '0',
  782.                           'chanceofovercast': '44',
  783.                           'chanceofrain': '0',
  784.                           'chanceofremdry': '90',
  785.                           'chanceofsnow': '0',
  786.                           'chanceofsunshine': '88',
  787.                           'chanceofthunder': '0',
  788.                           'chanceofwindy': '0',
  789.                           'cloudcover': '44',
  790.                           'diffRad': '0.0',
  791.                           'humidity': '20',
  792.                           'precipInches': '0.0',
  793.                           'precipMM': '0.0',
  794.                           'pressure': '1043',
  795.                           'pressureInches': '31',
  796.                           'shortRad': '0.0',
  797.                           'tempC': '-9',
  798.                           'tempF': '16',
  799.                           'time': '300',
  800.                           'uvIndex': '1',
  801.                           'visibility': '10',
  802.                           'visibilityMiles': '6',
  803.                           'weatherCode': '116',
  804.                           'weatherDesc': [{'value': 'Partly Cloudy '}],
  805.                           'weatherIconUrl': [{'value': ''}],
  806.                           'winddir16Point': 'N',
  807.                           'winddirDegree': '352',
  808.                           'windspeedKmph': '18',
  809.                           'windspeedMiles': '11'},
  810.                          {'DewPointC': '-28',
  811.                           'DewPointF': '-19',
  812.                           'FeelsLikeC': '-17',
  813.                           'FeelsLikeF': '2',
  814.                           'HeatIndexC': '-10',
  815.                           'HeatIndexF': '15',
  816.                           'WindChillC': '-17',
  817.                           'WindChillF': '2',
  818.                           'WindGustKmph': '21',
  819.                           'WindGustMiles': '13',
  820.                           'chanceoffog': '0',
  821.                           'chanceoffrost': '77',
  822.                           'chanceofhightemp': '0',
  823.                           'chanceofovercast': '50',
  824.                           'chanceofrain': '0',
  825.                           'chanceofremdry': '89',
  826.                           'chanceofsnow': '0',
  827.                           'chanceofsunshine': '63',
  828.                           'chanceofthunder': '0',
  829.                           'chanceofwindy': '0',
  830.                           'cloudcover': '65',
  831.                           'diffRad': '0.2',
  832.                           'humidity': '20',
  833.                           'precipInches': '0.0',
  834.                           'precipMM': '0.0',
  835.                           'pressure': '1043',
  836.                           'pressureInches': '31',
  837.                           'shortRad': '0.5',
  838.                           'tempC': '-10',
  839.                           'tempF': '15',
  840.                           'time': '600',
  841.                           'uvIndex': '1',
  842.                           'visibility': '10',
  843.                           'visibilityMiles': '6',
  844.                           'weatherCode': '122',
  845.                           'weatherDesc': [{'value': 'Overcast '}],
  846.                           'weatherIconUrl': [{'value': ''}],
  847.                           'winddir16Point': 'N',
  848.                           'winddirDegree': '350',
  849.                           'windspeedKmph': '16',
  850.                           'windspeedMiles': '10'},
  851.                          {'DewPointC': '-29',
  852.                           'DewPointF': '-19',
  853.                           'FeelsLikeC': '-16',
  854.                           'FeelsLikeF': '3',
  855.                           'HeatIndexC': '-9',
  856.                           'HeatIndexF': '15',
  857.                           'WindChillC': '-16',
  858.                           'WindChillF': '3',
  859.                           'WindGustKmph': '20',
  860.                           'WindGustMiles': '13',
  861.                           'chanceoffog': '0',
  862.                           'chanceoffrost': '76',
  863.                           'chanceofhightemp': '0',
  864.                           'chanceofovercast': '82',
  865.                           'chanceofrain': '0',
  866.                           'chanceofremdry': '86',
  867.                           'chanceofsnow': '0',
  868.                           'chanceofsunshine': '16',
  869.                           'chanceofthunder': '0',
  870.                           'chanceofwindy': '0',
  871.                           'cloudcover': '88',
  872.                           'diffRad': '43.7',
  873.                           'humidity': '19',
  874.                           'precipInches': '0.0',
  875.                           'precipMM': '0.0',
  876.                           'pressure': '1043',
  877.                           'pressureInches': '31',
  878.                           'shortRad': '113.2',
  879.                           'tempC': '-9',
  880.                           'tempF': '15',
  881.                           'time': '900',
  882.                           'uvIndex': '1',
  883.                           'visibility': '10',
  884.                           'visibilityMiles': '6',
  885.                           'weatherCode': '119',
  886.                           'weatherDesc': [{'value': 'Cloudy '}],
  887.                           'weatherIconUrl': [{'value': ''}],
  888.                           'winddir16Point': 'NNW',
  889.                           'winddirDegree': '347',
  890.                           'windspeedKmph': '15',
  891.                           'windspeedMiles': '10'},
  892.                          {'DewPointC': '-29',
  893.                           'DewPointF': '-20',
  894.                           'FeelsLikeC': '-14',
  895.                           'FeelsLikeF': '7',
  896.                           'HeatIndexC': '-7',
  897.                           'HeatIndexF': '19',
  898.                           'WindChillC': '-14',
  899.                           'WindChillF': '7',
  900.                           'WindGustKmph': '21',
  901.                           'WindGustMiles': '13',
  902.                           'chanceoffog': '0',
  903.                           'chanceoffrost': '76',
  904.                           'chanceofhightemp': '0',
  905.                           'chanceofovercast': '57',
  906.                           'chanceofrain': '0',
  907.                           'chanceofremdry': '85',
  908.                           'chanceofsnow': '0',
  909.                           'chanceofsunshine': '36',
  910.                           'chanceofthunder': '0',
  911.                           'chanceofwindy': '0',
  912.                           'cloudcover': '44',
  913.                           'diffRad': '85.2',
  914.                           'humidity': '16',
  915.                           'precipInches': '0.0',
  916.                           'precipMM': '0.0',
  917.                           'pressure': '1042',
  918.                           'pressureInches': '31',
  919.                           'shortRad': '297.8',
  920.                           'tempC': '-7',
  921.                           'tempF': '19',
  922.                           'time': '1200',
  923.                           'uvIndex': '2',
  924.                           'visibility': '10',
  925.                           'visibilityMiles': '6',
  926.                           'weatherCode': '113',
  927.                           'weatherDesc': [{'value': 'Sunny'}],
  928.                           'weatherIconUrl': [{'value': ''}],
  929.                           'winddir16Point': 'NNW',
  930.                           'winddirDegree': '338',
  931.                           'windspeedKmph': '18',
  932.                           'windspeedMiles': '11'},
  933.                          {'DewPointC': '-29',
  934.                           'DewPointF': '-20',
  935.                           'FeelsLikeC': '-12',
  936.                           'FeelsLikeF': '10',
  937.                           'HeatIndexC': '-6',
  938.                           'HeatIndexF': '22',
  939.                           'WindChillC': '-12',
  940.                           'WindChillF': '10',
  941.                           'WindGustKmph': '22',
  942.                           'WindGustMiles': '14',
  943.                           'chanceoffog': '0',
  944.                           'chanceoffrost': '67',
  945.                           'chanceofhightemp': '0',
  946.                           'chanceofovercast': '0',
  947.                           'chanceofrain': '0',
  948.                           'chanceofremdry': '90',
  949.                           'chanceofsnow': '0',
  950.                           'chanceofsunshine': '88',
  951.                           'chanceofthunder': '0',
  952.                           'chanceofwindy': '0',
  953.                           'cloudcover': '0',
  954.                           'diffRad': '67.4',
  955.                           'humidity': '14',
  956.                           'precipInches': '0.0',
  957.                           'precipMM': '0.0',
  958.                           'pressure': '1040',
  959.                           'pressureInches': '31',
  960.                           'shortRad': '312.4',
  961.                           'tempC': '-6',
  962.                           'tempF': '22',
  963.                           'time': '1500',
  964.                           'uvIndex': '2',
  965.                           'visibility': '10',
  966.                           'visibilityMiles': '6',
  967.                           'weatherCode': '113',
  968.                           'weatherDesc': [{'value': 'Sunny'}],
  969.                           'weatherIconUrl': [{'value': ''}],
  970.                           'winddir16Point': 'NNW',
  971.                           'winddirDegree': '328',
  972.                           'windspeedKmph': '18',
  973.                           'windspeedMiles': '11'},
  974.                          {'DewPointC': '-28',
  975.                           'DewPointF': '-18',
  976.                           'FeelsLikeC': '-12',
  977.                           'FeelsLikeF': '11',
  978.                           'HeatIndexC': '-6',
  979.                           'HeatIndexF': '22',
  980.                           'WindChillC': '-12',
  981.                           'WindChillF': '11',
  982.                           'WindGustKmph': '22',
  983.                           'WindGustMiles': '14',
  984.                           'chanceoffog': '0',
  985.                           'chanceoffrost': '50',
  986.                           'chanceofhightemp': '0',
  987.                           'chanceofovercast': '0',
  988.                           'chanceofrain': '0',
  989.                           'chanceofremdry': '86',
  990.                           'chanceofsnow': '0',
  991.                           'chanceofsunshine': '87',
  992.                           'chanceofthunder': '0',
  993.                           'chanceofwindy': '0',
  994.                           'cloudcover': '0',
  995.                           'diffRad': '38.5',
  996.                           'humidity': '16',
  997.                           'precipInches': '0.0',
  998.                           'precipMM': '0.0',
  999.                           'pressure': '1039',
  1000.                           'pressureInches': '31',
  1001.                           'shortRad': '191.1',
  1002.                           'tempC': '-6',
  1003.                           'tempF': '22',
  1004.                           'time': '1800',
  1005.                           'uvIndex': '1',
  1006.                           'visibility': '10',
  1007.                           'visibilityMiles': '6',
  1008.                           'weatherCode': '113',
  1009.                           'weatherDesc': [{'value': 'Clear '}],
  1010.                           'weatherIconUrl': [{'value': ''}],
  1011.                           'winddir16Point': 'NW',
  1012.                           'winddirDegree': '319',
  1013.                           'windspeedKmph': '15',
  1014.                           'windspeedMiles': '9'},
  1015.                          {'DewPointC': '-27',
  1016.                           'DewPointF': '-17',
  1017.                           'FeelsLikeC': '-12',
  1018.                           'FeelsLikeF': '10',
  1019.                           'HeatIndexC': '-7',
  1020.                           'HeatIndexF': '20',
  1021.                           'WindChillC': '-12',
  1022.                           'WindChillF': '10',
  1023.                           'WindGustKmph': '20',
  1024.                           'WindGustMiles': '13',
  1025.                           'chanceoffog': '0',
  1026.                           'chanceoffrost': '50',
  1027.                           'chanceofhightemp': '0',
  1028.                           'chanceofovercast': '0',
  1029.                           'chanceofrain': '0',
  1030.                           'chanceofremdry': '87',
  1031.                           'chanceofsnow': '0',
  1032.                           'chanceofsunshine': '90',
  1033.                           'chanceofthunder': '0',
  1034.                           'chanceofwindy': '0',
  1035.                           'cloudcover': '0',
  1036.                           'diffRad': '12.9',
  1037.                           'humidity': '18',
  1038.                           'precipInches': '0.0',
  1039.                           'precipMM': '0.0',
  1040.                           'pressure': '1039',
  1041.                           'pressureInches': '31',
  1042.                           'shortRad': '63.8',
  1043.                           'tempC': '-7',
  1044.                           'tempF': '20',
  1045.                           'time': '2100',
  1046.                           'uvIndex': '1',
  1047.                           'visibility': '10',
  1048.                           'visibilityMiles': '6',
  1049.                           'weatherCode': '113',
  1050.                           'weatherDesc': [{'value': 'Clear '}],
  1051.                           'weatherIconUrl': [{'value': ''}],
  1052.                           'winddir16Point': 'NW',
  1053.                           'winddirDegree': '318',
  1054.                           'windspeedKmph': '13',
  1055.                           'windspeedMiles': '8'}],
  1056.               'maxtempC': '-6',
  1057.               'maxtempF': '22',
  1058.               'mintempC': '-10',
  1059.               'mintempF': '14',
  1060.               'sunHour': '8.3',
  1061.               'totalSnow_cm': '0.0',
  1062.               'uvIndex': '2'}]}
复制代码
方法二:最正规法——看官方文档(API Docs)

        这是最推荐的方法,也是大公司(eg:OpenAI, 高德地图,微信支付)的做法。
        他们会提供一份详细的说明书,直接告诉你:"我的JSON长什么样,每个字段是什么意思。"
作为工程师的习惯:拿到一个API,第一反应先找文档,找不到文档(比如爬虫逆向时),再用其他方法。
方法三:浏览器F12(开发者工具)

        如果你在爬取一个网页的数据(没有文档),或者你想快速看一眼某个接口返回了什么。
OPERATION STEPS:
    打开浏览器(Chrome/Edge)按F12打开开发者工具点击顶部的"Network"(网络)标签刷新一下网页在过滤器里选择"Fetch/XHR"(这一步很关键,只看数据接口,不看图片/CSS)在左侧列表里找到那个请求,点击它点击右侧的"Preview"或"Response"
        浏览器会把JSON自动折叠好,可以像点文件夹一样一层层点开。这比python打印出来看还要直观!
方法四: AI辅助法

        只需要把那坨乱糟糟的JSON数据(用方法一打印出来),直接丢给AI
        Prompt 示例:
        “这是我从 API 拿到的 JSON 数据:[粘贴数据] 我想用 Python 提取出里面的‘当前气温’和‘天气描述’,请帮我写出解析代码。”
        AI直接给你写好
  1. # 解析JSON数据
  2. weather_data = {'current_condition': [{'FeelsLikeC': '-5', 'FeelsLikeF': '23', 'cloudcover': '0', 'humidity': '58', 'localObsDateTime': '2026-01-18 01:30 PM', 'observation_time': '05:30 AM', 'precipInches': '0.0', 'precipMM': '0.0', 'pressure': '1029', 'pressureInches': '30', 'temp_C': '-4', 'temp_F': '25', 'uvIndex': '1', 'visibility': '10', 'visibilityMiles': '6', 'weatherCode': '119', 'weatherDesc': [{'value': 'Cloudy'}], 'weatherIconUrl': [{'value': ''}], 'winddir16Point': 'S', 'winddirDegree': '180', 'windspeedKmph': '4', 'windspeedMiles': '2'}], 'nearest_area': [{'areaName': [{'value': 'Beijing'}], 'country': [{'value': 'China'}], 'latitude': '39.929', 'longitude': '116.388', 'population': '7480601', 'region': [{'value': 'Beijing'}], 'weatherUrl': [{'value': ''}]}], 'request': [{'query': 'Lat 39.91 and Lon 116.39', 'type': 'LatLon'}], 'weather': [{...}]}
  3. # 提取当前气温和天气描述
  4. temp = weather_data['current_condition'][0]['temp_C']  # 当前气温 = "-4"
  5. desc = weather_data['current_condition'][0]['weatherDesc'][0]['value']  # 天气描述 = "Cloudy"
复制代码
1.3.4 要点分析——requests.exceptions.RequestException

requests = 大工具箱 (Package/Folder).exceptions = 工具箱里的 “报错说明书”分区 (Module/File).RequestException = 说明书里的 第一条条款 (Class)“文件夹 -> 文件 -> 类”.
1.3.5 要点分析——(keyError, IndexError)

        出现原因
  1. # ... 之前已经拿到了 data 字典 ...
  2. # ⚠️ 风险代码 A
  3. current_condition = data['current_condition'][0]
  4. # ⚠️ 风险代码 B
  5. weather_desc = current_condition['weatherDesc'][0]['value']
  6. 2. KeyError (键错误) —— “查无此词”
复制代码
  KeyError

  1. '''
  2. 来源: 字典 (dict) 操作。
  3.         含义: 你想在字典里找一个 Key(键),但是字典里根本没有这个 Key。
  4.         在你的代码中是如何发生的?
  5.         你的代码写着:data['current_condition']。
  6.         这意味着你坚信 API 返回的 data 字典里一定有个叫 'current_condition' 的东西。
  7.         实际情况: 如果你输错了城市名(比如 "NoCity"),wttr.in 可能会返回这样一个报错用的 JSON:
  8. '''
  9. {
  10.     "error_message": "Unable to find any matching weather location."
  11. }
  12. # 结果: Python 拿着这个字典去找 'current_condition',发现没有!于是当场抛出 KeyError。
复制代码

IndexError

  1. # 来源: 列表 (list) 操作。
  2. '''
  3. 含义: 你想取列表里的第 N 个元素(比如第 0 个),但列表里的元素数量不够,或者列表根本是空的。
  4. 在你的代码中是如何发生的?
  5. 你的代码写着:['current_condition'][0] 或 ['weatherDesc'][0]。
  6. 那个 [0] 就是在取“第一个元素”。
  7. 实际情况: 假设 API 抽风了,返回了这样一个结构:
  8. '''
  9. {
  10.     "current_condition": []  # 注意!这里是个空列表
  11. }
  12. # 结果: 代码试图从空列表里拿第 1 个元素 ([0]),但箱子是空的。Python 就会抛出 IndexError: list index out of range。
  13. # 比喻: 就像一本书只有 10 页,你却非要翻到第 11 页,或者一本书全是白纸你非要读第一行的字。
复制代码
  1. # 为什么要把它们放在一起?
  2. except (KeyError, IndexError) as e:
  3. # 因为对于你(开发者)来说,无论是“找不到键”还是“列表为空”,后果是一样的:
  4. # 结论: 数据格式不对,我没法提取天气信息。
  5. # 处理方式: 统统归类为 “数据解析失败”。
复制代码
原文地址:https://blog.csdn.net/weixin_63840907/article/details/157094316
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

发布主题
阅读排行更多+

Powered by Discuz! X3.4© 2001-2013 Discuz Team.( 京ICP备17022993号-3 )