用于与位置交互的python实用程序
ctodd-python-lib-location的Python项目详细描述
Christopher H.Todd的用于与位置交互的Python库
ctodd python库位置项目负责管理位置信息、地理编码地址和获取方向。
目录
依赖关系
Python包
- 地理编码器==1.38.1
- 请求数==2.22.0
- 街道地址==0.4.0
- usaddress==0.5.10
库
address_helpers.py
地址助手。此库用于与地址字符串/dict交互并转换/处理这些地址。
功能:
def convert_string_address_to_dict(address_string, expected_fields=None):
"""
Purpose:
Parse a string into an address dict with specific fields
Args:
address_string (String): Raw address string to try and parse
expected_fields (List): List of fields that are needed to be parsed to be
considered successful
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
def parse_address_using_lib_usaddress(address_string):
"""
Purpose:
Use the usaddress library to parse a string into a dict
Args:
address_string (String): Raw address string to try and parse
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
def parse_address_using_lib_streetaddress(address_string):
"""
Purpose:
Use the street-address library to parse a string into a dict
Args:
address_string (String): Raw address string to try and parse
Return:
parsed_address (Dict): Dict of the parsed address with fields that could be
determined from a string
"""
mapquest_helpers.py
地图任务助手此库用于包装MapQuest API调用并处理身份验证
功能:
def get_mapquest_api_key(public_key_file="~/.mapquest/public_key.txt"):
"""
Purpose:
Get the mapquest API from the environment
Args:
public_key_file (String): filename of the public key token file
Return:
mapquest_api_key (String): MapQuest public key
"""
def get_directions_between_two_addresses(mapquest_api_key, address_1, address_2):
"""
Purpose:
Get directions between two addresses
Leverages Mapquest API:
https://developer.mapquest.com/documentation/directions-api/route/get/
Args:
address_1 (String): Address to use as start point of travel
address_2 (String): Address to use as end destination of travel
Return:
directions (Dict): Dict of the directions between the two locations
"""
示例脚本
用于测试和与库交互的示例可执行python脚本/模块。这些示例显示了库的用例,可以用作与库一起开发的模板,也可以用作一次性开发工作
parse_addresses.py
Purpose:
Parse some set addresses
Steps:
- Parse Args
- Call libs to parse addresses
function call:
python3.6 parse_addresses \
[-h] \
--addresses ADDRESSES
example script call:
python3.6 example_usage/parse_addresses.py \
--address="REDACTED" \
--address="REDACTED"
get_directions_between_addresses.py
Purpose:
Get Directions between two addresses.
Steps:
- Parse Args
- Call libs to get directions from args
- Parse directions for some valuable information
function call:
python3.6 get_directions_between_addresses.py \
[-h] \
--start-address START_ADDRESS \
--end-address END_ADDRESS
example script call:
python3.6 example_usage/get_directions_between_addresses.py \
--start-address="REDACTED" \
--end-address="REDACTED"
注释
- 依赖于f-string符号,它仅限于python3.6。通过重构删除这些内容,可以使用python3.0.x到3.5.x进行开发
待办事项
- UnitTest框架已就位,但缺少测试