dferrante / pywx

python weather bot
10 stars 3 forks source link

lastquake command fails if there's no numerical value to the earthquake location in USGS feed #19

Open dziban303 opened 5 years ago

dziban303 commented 5 years ago

https://github.com/dferrante/pywx/blob/ddb470cff9451379f9de6273e9d49d3f7438af55/pywx/modules/earthquake.py#L20

'lastquake' command throws exception if the latest significant earthquake in the USGS feed doesn't include a distance in the 'place' field.

Latest quake shows: {"mag":6.3,"place":"Southern East Pacific Rise","time":1542323341050

Note lack of "303km from Dzibania"-style distance measurement.

Regex should be amended to handle a lack of km to convert.

Exception is 2018-11-16 23:52:30,005 ERROR 'NoneType' object has no attribute 'group' Traceback (most recent call last): File "/mnt/c/linux/dziwx/pywx/modules/base.py", line 88, in run context = self.context(msg) File "/mnt/c/linux/dziwx/pywx/modules/earthquake.py", line 90, in context return self.quake_context(earthquakes[0]) File "/mnt/c/linux/dziwx/pywx/modules/earthquake.py", line 52, in quake_context 'region': label_km_to_miles(eqp['place']), File "/mnt/c/linux/dziwx/pywx/modules/earthquake.py", line 20, in <lambda> label_km_to_miles = lambda s: re.sub(r'[0-9.]+\s?km', '%s (%smi)' % (re.compile(r'([0-9.]+)\s?km').match(s).group(0), km_to_miles(re.compile(r'([0-9.]+)\s?km').match(s).group(1))), s) AttributeError: 'NoneType' object has no attribute 'group'