fuelwatch.wa.gov.au燃油价格的简单xml刮刀
fuelwatcher的Python项目详细描述
______ __ __ __
/ ____/_ _____ / / ______ _/ /______/ /_ ___ _____
/ /_ / / / / _ \/ / | /| / / __ `/ __/ ___/ __ \/ _ \/ ___/
/ __/ / /_/ / __/ /| |/ |/ / /_/ / /_/ /__/ / / / __/ /
/_/ \__,_/\___/_/ |__/|__/\__,_/\__/\___/_/ /_/\___/_/ v 0.2.0
燃油观察者
一个简单的python模块,它从西澳大利亚州政府的fuelwatch计划网站上收集xml数据,使得解析变得轻而易举。
Fuelwatch.wa.gov.au provides information on fuel prices by fuel type, location, brand and region within Western Australia. Fuelwatcher will parse the XML from the fuelwatch.wa.gov.au RSS feed giving the developer an easy way to manipulate the information.
安装
要求安装pip
,或pip3
依赖于系统或环境。
仅限python 3
pip install fuelwatcher
用法示例
基本用法
fromfuelwatchimportFuelWatchapi=FuelWatch()api.query(product=2,region=25,day='yesterday')# returns byte string of xml.xml_query=api.get_xml# iterates over each fuel station entry in the byte string# and returns list of dictionaries in human readable text.print(parsed_query)>>>>[{'title':'138.5: Puma Bayswater','description':'Address: 502 Guildford Rd, BAYSWATER, Phone: (08) 9379 1322, Open 24 hours','brand':'Puma','date':'2018-04-05','price':'138.5','trading-name':'Puma Bayswater','location':'BAYSWATER','address':'502 Guildford Rd','phone':'(08) 9379 1322','latitude':'-31.919556','longitude':'115.929069','site-features':', Open 24 hours'}..snip..]
fuelwatcher还可以将xml转换为json格式。它与调用get_json
方法一样简单。
api=FuelWatch()api.query(region=1)json_response=api.get_json>>>>[>>>>{>>>>"title":"143.9: United Boulder Kalgoorlie",>>>>"description":"Address: Cnr Lane St & Davis St, BOULDER, Phone: (08) 9093 1543",>>>>"brand":"United",>>>>"date":"2018-04-13",>>>>"price":"143.9",>>>>...snip...>>>>"longitude":"121.433746",>>>>"site-features":"Unmanned Station, ">>>>}>>>>]
对于大多数操作,get_xml()
或get_json()
方法就足够了。如果开发人员想要解析原始rss xml,那么可以使用get_raw()
方法。
get_raw=api.get_rawprint(get_raw)>>>>(b'<?xml version="1.0" encoding="UTF-8"?>\r\n<rss version="2.0"><channel><title>FuelWatch Prices For North of River</title><ttl>720</ttl><link>http://www.fuelwatch.wa.gov.au</link><description>05/04/2018 - North of River</description><language>en-us</language><copyright>Copyright 2005 FuelWatch... snip...</item></channel></rss>\r\n')
查询方法接受几个关键字参数。默认情况下,它将返回整个西澳大利亚的每个加油站。
由于引导查询采用以下Kwargs
defquery(self,product:int=None,suburb:str=None,region:int=None,brand:int=None,surrounding:str=None,day:str=None):
如果设置了suburb
,那么surrounding
可以设置为no
或保留为None
;它在api端点默认为yes
。使用suburb
和surrounding
设置region
将产生意外结果,最好保留默认设置。
简单地说,如果只需要一个suburb
,那么设置surrounding='no'
否则保留默认值。每个查询只能设置一个suburb
。如果选择了region
,则不要设置surrounding
或suburb
没有意义吗?试试这张桌子。
PARAMETERS | OPTION 1 | OPTION 2 |
---|---|---|
suburb | Y | N |
region | N | Y |
surrounding | Y or N | N |
product | Y | Y |
brand | Y | Y |
day | Y | Y |
有效的郊区、品牌、地区和产品(燃料类型)列表可在constants.py
FuelWatcher将对query
方法运行验证,并抛出断言错误为无效整数或输入字符串
api.query(product=20)# product=20 is invalid>>>....errorsnippet....>>>AssertionError:InvalidProductInteger.
发布历史记录
- 0.2.0条
- 制动改变!
- @属性添加了raw、xml和json方法
- 现在支持json输出
- 0.1.1条
- 在setup.py中包含正确的包
- 0.1.0条
- 第一次发布到pypi
- 0.1.0平方厘米
- 小格式修复
- 0.1.0RC1号
- 第一个候选版本
- 0.0.1分
- 进行中的工作
元
丹尼尔·迈克尔斯–https://www.danielms.site
根据麻省理工学院的许可证发行。有关详细信息,请参见LICENSE
。
贡献
欢迎所有的要求,想法或改进!
- 叉开它
- 创建功能分支(
git checkout -b feature/fooBar
) - 提交更改(
git commit -am 'Add some fooBar'
) - 推到分支(
git push origin feature/fooBar
) - 创建新的拉取请求
灵感来源于..
一个本地python meetup组的想法,变成了一个pypi包供任何人使用!