Update weather.com backend to reflect upstream changes (#788)
Weather.com embeds the weather data as a JSON in a <script> tag, so this just updates to reflect recent changes to how that information is embedded. Co-authored-by: Erik Johnson <erik.johnson@centurylink.com>
This commit is contained in:
parent
1f8b0a7863
commit
a7c24e43b2
@ -70,9 +70,12 @@ class WeathercomHTMLParser(HTMLParser):
|
||||
weather_data = None
|
||||
self.logger.debug('Located window.__data')
|
||||
# Strip the "window.__data=" from the beginning and load json
|
||||
json_data = self.load_json(
|
||||
content[begin:].split('=', 1)[1].lstrip()
|
||||
)
|
||||
raw_json = content[begin:].split('=', 1)[1].lstrip()
|
||||
if re.match(r'^JSON\.parse\("', raw_json):
|
||||
raw_json = re.sub(r'^JSON\.parse\("', '', raw_json)
|
||||
raw_json = re.sub(r'"\);?$', '', raw_json)
|
||||
raw_json = raw_json.replace(r'\"', '"').replace(r'\\', '\\')
|
||||
json_data = self.load_json(raw_json)
|
||||
if json_data is not None:
|
||||
try:
|
||||
weather_data = json_data['dal']
|
||||
|
Loading…
Reference in New Issue
Block a user