With the GeoNet problem I had now fixed I am also getting distances to earthquake locations in miles, when the rest of my site is km
Thanks Colin On Fri, 25 Dec 2020, 23:35 moth...@gmail.com, <mothe...@gmail.com> wrote: > yes, it works, thanks for the adjustment. > Ton > http://weerstationnibbixwoud.nl/ > > Op woensdag 28 oktober 2020 om 18:45:37 UTC+1 schreef blee...@xs4all.nl: > >> Hallo Arend, >> >> Yes, it's working! >> >> Just aligning the new line after #25-10.4 solved the problem, manymany >> thanks! >> >> Best regards, Keimpe >> >> Op woensdag 28 oktober 2020 om 15:31:29 UTC+1 schreef Arend: >> >>> Hi Keimpe, >>> >>> I have a suspicion why it didn't work out for you. Copying your code >>> from your previous post into a text editor revealed that the changes you >>> made were not properly alligned. The Python language is sensitive to >>> indentation. The screenshot below shows a green and red line. The second >>> eqmag (#25-10.4) should have been lined up to the green line like the first >>> eqmag (#25-10.3). But instead it was lined up to the red line, probably >>> causing an exception (error) which would result in displaying that there >>> was no earthquake data available. >>> >>> [image: Toelichting uitlijning code.png] >>> >>> I have included a new version of belchertown.py that has already been >>> modified with the correct changes. Could you be so kind to download this >>> file and use it to replace the existing belchertown.py. If this works then >>> I will use this file for a pull request. >>> >>> >>> Mvg, Arend >>> >>> >>> Op woensdag 28 oktober 2020 om 11:38:34 UTC+1 schreef blee...@xs4all.nl: >>> >>>> Hoi Arend, >>>> >>>> Thanks for your efforts. >>>> >>>> Now changed back to the original file and (of cours) the EQ data is >>>> back, as expected in 'mijl'. >>>> In the log there is no related error, the only recursive error is a >>>> Failed to publish record .... to WOW. >>>> Undermentioned you may find the earthquake section of belchertown.py >>>> with the recommended changes. Between empty lines the original lines ar >>>> commented out with #25-10.1 (#date and 1 is the line-number as suggested in >>>> your GitHub post), following the line copied from GitHub. >>>> >>>> Regards, Keimpe >>>> >>>> >>>> """ >>>> Earthquake Data >>>> """ >>>> # Only process if Earthquake data is enabled >>>> if self.generator.skin_dict['Extras']['earthquake_enabled'] == >>>> "1": >>>> earthquake_file = html_root + "/json/earthquake.json" >>>> earthquake_stale_timer = >>>> self.generator.skin_dict['Extras']['earthquake_stale'] >>>> latitude = self.generator.config_dict['Station']['latitude'] >>>> longitude = >>>> self.generator.config_dict['Station']['longitude'] >>>> >>>> #25-10.1 distance_unit = converter.group_unit_dict["group_distance"] >>>> distance_unit = >>>> self.generator.converter.group_unit_dict["group_distance"] >>>> >>>> eq_distance_label = >>>> self.generator.skin_dict['Units']['Labels'].get(distance_unit, "") >>>> eq_distance_round = >>>> self.generator.skin_dict['Units']['StringFormats'].get(distance_unit, >>>> "%.1f") >>>> earthquake_maxradiuskm = >>>> self.generator.skin_dict['Extras']['earthquake_maxradiuskm'] >>>> #Sample URL from Belchertown Weather: >>>> http://earthquake.usgs.gov/fdsnws/event/1/query?limit=1&lat=42.223&lon=-72.374&maxradiuskm=1000&format=geojson&nodata=204&minmag=2 >>>> if self.generator.skin_dict['Extras']['earthquake_server'] >>>> == "USGS": >>>> earthquake_url = " >>>> http://earthquake.usgs.gov/fdsnws/event/1/query?limit=1&lat=%s&lon=%s&maxradiuskm=%s&format=geojson&nodata=204&minmag=2" >>>> % ( latitude, longitude, earthquake_maxradiuskm ) >>>> elif >>>> self.generator.skin_dict['Extras']['earthquake_server'] == "GeoNet": >>>> earthquake_url = "https://api.geonet.org.nz/quake?MMI=4 >>>> " >>>> earthquake_is_stale = False >>>> >>>> # Determine if the file exists and get it's modified time >>>> if os.path.isfile( earthquake_file ): >>>> if ( int( time.time() ) - int( os.path.getmtime( >>>> earthquake_file ) ) ) > int( earthquake_stale_timer ): >>>> earthquake_is_stale = True >>>> else: >>>> # File doesn't exist, download a new copy >>>> earthquake_is_stale = True >>>> >>>> # File is stale, download a new copy >>>> if earthquake_is_stale: >>>> # Download new earthquake data >>>> try: >>>> try: >>>> # Python 3 >>>> from urllib.request import Request, urlopen >>>> except ImportError: >>>> # Python 2 >>>> from urllib2 import Request, urlopen >>>> user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac >>>> OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 >>>> Safari/534.3' >>>> headers = { 'User-Agent' : user_agent } >>>> req = Request( earthquake_url, None, headers ) >>>> response = urlopen( req ) >>>> page = response.read() >>>> response.close() >>>> if weewx.debug: >>>> logdbg( "Downloading earthquake data using >>>> urllib2 was successful" ) >>>> except Exception as forecast_error: >>>> if weewx.debug: >>>> logdbg( "Error downloading earthquake data with >>>> urllib2, reverting to curl and subprocess. Full error: %s" % forecast_error >>>> ) >>>> # Nested try - only execute if the urllib2 method >>>> fails >>>> try: >>>> import subprocess >>>> command = 'curl -L --silent "%s"' % >>>> earthquake_url >>>> p = subprocess.Popen(command, shell=True, >>>> stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >>>> page = p.communicate()[0] >>>> if weewx.debug: >>>> logdbg( "Downloading earthquake data with >>>> curl was successful." ) >>>> except Exception as error: >>>> raise Warning( "Error downloading earthquake >>>> data using urllib2 and subprocess curl. Your software may need to be >>>> updated, or the URL is incorrect. You are trying to use URL: %s, and the >>>> error is: %s" % ( earthquake_url, error ) ) >>>> >>>> # Save earthquake data to file. w+ creates the file if >>>> it doesn't exist, and truncates the file and re-writes it everytime >>>> try: >>>> with open( earthquake_file, 'wb+' ) as file: >>>> # Python 2/3 >>>> try: >>>> file.write( page.encode('utf-8') ) >>>> except: >>>> file.write( page ) >>>> if weewx.debug: >>>> logdbg( "Earthquake data saved to %s" % >>>> earthquake_file ) >>>> except IOError as e: >>>> raise Warning( "Error writing earthquake data to >>>> %s. Reason: %s" % ( earthquake_file, e) ) >>>> >>>> # Process the earthquake file >>>> with open( earthquake_file, "r" ) as read_file: >>>> try: >>>> eqdata = json.load( read_file ) >>>> except: >>>> eqdata = "" >>>> >>>> try: >>>> if >>>> self.generator.skin_dict['Extras']['earthquake_server'] == "USGS": >>>> eqtime = >>>> eqdata["features"][0]["properties"]["time"] / 1000 >>>> equrl = eqdata["features"][0]["properties"]["url"] >>>> eqplace = >>>> eqdata["features"][0]["properties"]["place"] >>>> >>>> #25-10.3 eqmag = eqdata["features"][0]["properties"]["mag"] >>>> eqmag = locale.format("%g", >>>> float(eqdata["features"][0]["properties"]["mag"]) ) >>>> >>>> elif >>>> self.generator.skin_dict['Extras']['earthquake_server'] == "GeoNet": >>>> eqtime = eqdata["features"][0]["properties"]["time"] >>>> #convert time to UNIX format >>>> eqtime = eqtime.replace("Z","") >>>> eqtime = datetime.datetime.fromisoformat(eqtime) >>>> eqtime = >>>> int(eqtime.replace(tzinfo=datetime.timezone.utc).timestamp()) >>>> equrl = ("https://www.geonet.org.nz/earthquake/" + >>>> >>>> eqdata["features"][0]["properties"]["publicID"]) >>>> eqplace = >>>> eqdata["features"][0]["properties"]["locality"] >>>> >>>> #25-10.4 eqmag = >>>> round(eqdata["features"][0]["properties"]["magnitude"],1) >>>> eqmag = locale.format("%g", >>>> float(round(eqdata["features"][0]["properties"]["magnitude"],1)) ) >>>> >>>> eqlat = str( round( >>>> eqdata["features"][0]["geometry"]["coordinates"][1], 4 ) ) >>>> eqlon = str( round( >>>> eqdata["features"][0]["geometry"]["coordinates"][0], 4 ) ) >>>> eqdistance_bearing = >>>> self.get_gps_distance((float(latitude), float(longitude)), >>>> >>>> (float(eqlat), float(eqlon)), >>>> >>>> distance_unit) >>>> >>>> #25-10.2 eqdistance = eq_distance_round % eqdistance_bearing[0] >>>> eqdistance = locale.format("%g", >>>> float(eq_distance_round % eqdistance_bearing[0]) ) >>>> >>>> eqbearing = eqdistance_bearing[1] >>>> eqbearing_raw = eqdistance_bearing[2] >>>> except: >>>> # No earthquake data >>>> eqtime = label_dict["earthquake_no_data"] >>>> equrl = "" >>>> eqplace = "" >>>> eqmag = "" >>>> eqlat = "" >>>> eqlon = "" >>>> eqdistance = "" >>>> eqbearing = "" >>>> eqbearing_raw = "" >>>> >>>> else: >>>> eqtime = "" >>>> equrl = "" >>>> eqplace = "" >>>> eqmag = "" >>>> eqlat = "" >>>> eqlon = "" >>>> eqdistance = "" >>>> eqbearing = "" >>>> eqbearing_raw = "" >>>> eq_distance_label = "" >>>> >>>> >>>> Op dinsdag 27 oktober 2020 om 22:54:22 UTC+1 schreef Arend: >>>> >>>>> I am going to make a pull request out of this issue, hopefully Pat >>>>> will incorporate this fix into the master. That way you will be able to >>>>> download it from the repository. >>>>> In the mean time you could try to replace the modified file with the >>>>> original from the repo and see what happens. Did you check your logs for >>>>> errors? >>>>> >>>>> Mvg, Arend >>>>> >>>>> Op dinsdag 27 oktober 2020 om 21:36:04 UTC+1 schreef blee...@xs4all.nl >>>>> : >>>>> >>>>>> Hi Arend, >>>>>> >>>>>> Thanks for the suggestions. >>>>>> >>>>>> - The JSON tels me about an eartquake 6 km E of Belle-Plagne in >>>>>> France, and lat=53.254&lon=5.895&maxradiuskm=2000 as set in my config, >>>>>> seems OK to me. >>>>>> - The config is same as yours >>>>>> - I checked the changes in belchertown.py, the only difference with >>>>>> your fixes is the order of the 4 lines, they do not come across these >>>>>> consecutively from top to bottom as you suggested, but first 1 (line >>>>>> 1060), >>>>>> then 3 (line 1139), then 4 (line 1152) and finally 2 (line 1161). I >>>>>> copy/pasted the lines (again) from GitHub in the editor. >>>>>> >>>>>> And still no data... >>>>>> >>>>>> Regards, Keimpe >>>>>> >>>>>> Op dinsdag 27 oktober 2020 om 20:51:31 UTC+1 schreef Arend: >>>>>> >>>>>>> Goedenavond Keimpe, >>>>>>> >>>>>>> You can check your earthquake file typing this into your browser: >>>>>>> >>>>>>> http://oentsjerk.eu/json/earthquake.json >>>>>>> >>>>>>> It shows the same data as mine which means it is loaded/updated >>>>>>> correctly, check the epoch timestamp to verify when it was >>>>>>> downloaded/updated. >>>>>>> Are you sure you copied the changes the right way (without >>>>>>> additional tabs or spaces)? >>>>>>> Are there no errors in your logs? >>>>>>> My configuration shows this: >>>>>>> >>>>>>> # Earthquake defaults >>>>>>> earthquake_enabled = 1 >>>>>>> earthquake_maxradiuskm = 2000 >>>>>>> earthquake_stale = 10740 >>>>>>> earthquake_server = USGS >>>>>>> >>>>>>> Does it match yours? >>>>>>> >>>>>>> Mvg, Arend >>>>>>> >>>>>>> Op dinsdag 27 oktober 2020 om 19:30:46 UTC+1 schreef >>>>>>> blee...@xs4all.nl: >>>>>>> >>>>>>>> Hi Arend, >>>>>>>> >>>>>>>> Stil no recent earthquake data avilable (http://oentsjerk.eu). Can >>>>>>>> I have your URL to check the actuality? >>>>>>>> >>>>>>>> Regards, Keimpe >>>>>>>> >>>>>>>> >>>>>>>> Op zondag 25 oktober 2020 om 11:46:06 UTC+1 schreef >>>>>>>> blee...@xs4all.nl: >>>>>>>> >>>>>>>>> Goedemiddag Arend, >>>>>>>>> >>>>>>>>> Thnx, changes made! >>>>>>>>> At this time it says 'no recent data avilabale' so I have to wait >>>>>>>>> for een eartqauke data-update. >>>>>>>>> Keep you informed. >>>>>>>>> >>>>>>>>> Regards, Keimpe >>>>>>>>> >>>>>>>>> Op zaterdag 24 oktober 2020 om 21:46:02 UTC+2 schreef Arend: >>>>>>>>> >>>>>>>>>> Hi Keimpe, >>>>>>>>>> >>>>>>>>>> I had the same problem and created an issue about this in the >>>>>>>>>> repo. You can use the fix, let me know if it works for you. >>>>>>>>>> >>>>>>>>>> https://github.com/poblabs/weewx-belchertown/issues/422 >>>>>>>>>> >>>>>>>>>> Mvg, Arend >>>>>>>>>> >>>>>>>>>> Op zaterdag 24 oktober 2020 om 21:04:04 UTC+2 schreef >>>>>>>>>> blee...@xs4all.nl: >>>>>>>>>> >>>>>>>>>>> Thnx Vince, Strange, also on mobile, WLAN and 4G network, the >>>>>>>>>>> same problem so it can't be a localization issue related to the >>>>>>>>>>> network. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Op zaterdag 24 oktober 2020 om 20:49:37 UTC+2 schreef vince: >>>>>>>>>>> >>>>>>>>>>>> On Saturday, October 24, 2020 at 10:47:03 AM UTC-7, >>>>>>>>>>>> blee...@xs4all.nl wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> I'm facing just a minor issue: in the skin.conf is defined >>>>>>>>>>>>> 'earthquake_maxradiuskm = 2000'. Therefore I'm expecting a >>>>>>>>>>>>> distance in >>>>>>>>>>>>> km's, but the actual distance as well as the units are still in >>>>>>>>>>>>> miles (mijl >>>>>>>>>>>>> in Dutch). How to resolve this? (http://oentsjerk.eu/) >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>> I see km when I look at your page. >>>>>>>>>>>> >>>>>>>>>>> -- > You received this message because you are subscribed to the Google Groups > "weewx-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to weewx-user+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/weewx-user/a4225415-7a3f-4842-9056-c85738b47d0an%40googlegroups.com > <https://groups.google.com/d/msgid/weewx-user/a4225415-7a3f-4842-9056-c85738b47d0an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CACjxfUsx6vzdVjP3CN3%2BGh_pVgKkgBKdaBcS1Cj05UBiefKu_A%40mail.gmail.com.