源代码: https://github.com/ma0513207162/PyPrecip。pyprecip\reading\read_api.py 路径下。
项目介绍:PyPrecip 是一个专注于气候数据处理的 Python 库,旨在为用户提供方便、高效的气候数据处理和分析工具。该库致力于处理各种气候数据,并特别关注于降水数据的处理和分析。
高德申请 Key
地址: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
个人申请 Key 很简单, 按照官方教程即可。
脚本介绍
导入相关的库和模块,用于支持程序的正常运行。包含自定义的异常抛出、警告、request请求、参数检查等。
import json
from requests.exceptions import RequestException
from ..utits.http_ import send_request
from ..utits.sundries import check_param_type
from ..utits.except_ import RaiseException as exc
from ..utits.warn_ import RaiseWarn as warn
WEATHER_KEY = ""
__check_weather_key 装饰器:检查全局变量 WEATHER_KEY 是否存在,如果不存在,打印相关提示。
# private decorator
def __check_weather_key(func):
def wrapper(*args, **kwargs):
"""
Check whether the global variable WEATHER_KEY is empty, and if it is,
prompt the user to register a Web service API and assign a value.
"""
if not WEATHER_KEY:
print("\033[93m- PyPrecip Warning: \033[0mWEATHER_KEY is not set.")
print("\033[0m- Please register for a Web Service API at\033[94m https://console.amap.com/dev/key/app.")
print("\033[0m- After registering, set the value of the global variable 'read_api.WEATHER_KEY' like this:")
print("\033[92m- read_api.WEATHER_KEY = 'your_api_key_here' \033[0m")
return;
return func(*args, **kwargs)
return wrapper
get_address_info 函数:在区域名正确的前提下,用于获取输入区域名来获取该区域的相关信息。
@__check_weather_key
def get_address_info(address: str = "", city: str = None) -> dict:
"""
The Amap geocoding service API is encapsulated to obtain the region code based on the provided address information.
Parameters
-
PyPrecip:Python库中的气候数据获取与APIKey管理

最低0.47元/天 解锁文章
711





