Skip to content

Commit

Permalink
Update weather.com backend to reflect upstream changes (#788)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
terminalmage and Erik Johnson authored Jul 31, 2020
1 parent 1f8b0a7 commit a7c24e4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions i3pystatus/weather/weathercom.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ def handle_data(self, content):
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']
Expand Down

0 comments on commit a7c24e4

Please sign in to comment.