I am trying to modify my custom component to extract some extra data from the xml returned.
Here is the xml (part of it) as an example
<?xml version="1.0" encoding="UTF-8"?>
<product version="1.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.bom.gov.au/schema/v1.7/product.xsd">
<amoc>
<source>
<sender>Australian Government Bureau of Meteorology</sender>
<region>New South Wales</region>
<office>NSWRO</office>
<copyright>http://www.bom.gov.au/other/copyright.shtml</copyright>
<disclaimer>http://www.bom.gov.au/other/disclaimer.shtml</disclaimer>
</source>
<identifier>IDN11052</identifier>
<issue-time-utc>2019-11-10T17:51:59Z</issue-time-utc>
<issue-time-local tz="EDT">2019-11-11T04:51:59+11:00</issue-time-local>
<sent-time>2019-11-10T17:51:59Z</sent-time>
<expiry-time>2019-11-11T17:51:59Z</expiry-time>
<validity-bgn-time-local tz="EDT">2019-11-11T00:00:00+11:00</validity-bgn-time-local>
<validity-end-time-local tz="EDT">2019-11-17T23:59:59+11:00</validity-end-time-local>
<next-routine-issue-time-utc>2019-11-11T05:25:00Z</next-routine-issue-time-utc>
<next-routine-issue-time-local tz="EDT">2019-11-11T16:25:00+11:00</next-routine-issue-time-local>
<status>O</status>
<service>WSP</service>
<sub-service>FCT</sub-service>
<product-type>F</product-type>
<phase>NEW</phase>
</amoc>
<forecast>
<area aac="NSW_FA001" description="New South Wales" type="region">
<forecast-period start-time-local="2019-11-11T04:52:00+11:00" end-time-local="2019-11-11T04:52:00+11:00" start-time-utc="2019-11-10T17:52:00Z" end-time-utc="2019-11-10T17:52:00Z">
<text type="warning_summary_footer">Details of warnings are available on the Bureau's website www.bom.gov.au, by telephone 1300-659-218* or through some TV and radio broadcasts.</text>
<text type="product_footer">* Calls to 1300 numbers cost around 27.5c incl. GST, higher from mobiles or public phones.</text>
</forecast-period>
</area>
<area aac="NSW_ME004" description="Central Coast" type="metropolitan" parent-aac="NSW_FA001">
<forecast-period index="0" start-time-local="2019-11-11T00:00:00+11:00" end-time-local="2019-11-12T00:00:00+11:00" start-time-utc="2019-11-10T13:00:00Z" end-time-utc="2019-11-11T13:00:00Z">
<text type="forecast">Mostly sunny. Light winds becoming northeasterly 30 to 45 km/h in the middle of the day then tending northerly 20 to 30 km/h in the late evening.</text>
<text type="fire_danger">Very High</text>
<text type="uv_alert">Sun protection 8:40am to 4:00pm, UV Index predicted to reach 10 [Very High]</text>
</forecast-period>
I am trying to extract the fire_danger and uv_alert. I can extract the forecast line directly above but just canât get the other 2.
The py is here
class BOMForecastData:
"""Get data from BOM."""
def __init__(self, product_id):
"""Initialize the data object."""
self._product_id = product_id
def get_reading(self, condition, index):
"""Return the value for the given condition."""
if condition == 'detailed_summary':
if PRODUCT_ID_LAT_LON_LOCATION[self._product_id][3] == 'City':
detailed_summary = self._data.find(_FIND_QUERY_2.format(index)).text
else:
detailed_summary = self._data.find(_FIND_QUERY.format(index, 'forecast')).text
return (detailed_summary[:251] + '...') if len(detailed_summary) > 251 else detailed_summary
find_query = (_FIND_QUERY.format(index, SENSOR_TYPES[condition][0]))
state = self._data.find(find_query)
if condition == 'icon':
return ICON_MAPPING[state.text]
"""
if condition == 'uv_alert':
uv_alert = self._data.find(_FIND_QUERY.format(index, 'uv_alert')).text
return uv_alert
if condition == 'fire_danger':
fire_danger = self._data.find(_FIND_QUERY.format(index, 'fire_danger')).text
return fire_danger
"""
if state is None:
if condition == 'possible_rainfall':
return '0 mm'
return 'n/a'
s = state.text
return (s[:251] + '...') if len(s) > 251 else s
Iâm commenting out the non-working linesâŚ
The full component is hereâŚ