Skip to content

Commit

Permalink
Add option to enable/disable weather alerts. Default is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
poblabs committed Dec 27, 2018
1 parent d967903 commit a725478
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/user/belchertown.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ def get_extension_list(self, timespan, db_lookup):
darksky_lang = self.generator.skin_dict['Extras']['darksky_lang'].lower()
latitude = self.generator.config_dict['Station']['latitude']
longitude = self.generator.config_dict['Station']['longitude']
forecast_stale_timer = self.generator.skin_dict['Extras']['forecast_stale']
forecast_alert_enabled = int( self.generator.skin_dict['Extras']['forecast_alert_enabled'] )
forecast_alert_length = int( self.generator.skin_dict['Extras']['forecast_alert_length'] )
forecast_stale_timer = self.generator.skin_dict['Extras']['forecast_stale']
forecast_is_stale = False

forecast_url = "https://api.darksky.net/forecast/%s/%s,%s?units=%s&lang=%s" % ( darksky_secret_key, latitude, longitude, darksky_units, darksky_lang )
Expand Down Expand Up @@ -482,15 +483,16 @@ def get_extension_list(self, timespan, db_lookup):
with open( forecast_file, "r" ) as read_file:
data = json.load( read_file )

# Weather Alerts
# Weather Alerts (only if enabled)
forecast_alert_text = ""
if "alerts" in data:
if len( data['alerts'][0]['description'] ) > forecast_alert_length:
forecast_alert_description = data['alerts'][0]['description'][:forecast_alert_length] + '...'
else:
forecast_alert_description = data['alerts'][0]['description']
# Final alert string
forecast_alert_text = "<strong>" + data['alerts'][0]['title'] + ":</strong> <a href='"+data['alerts'][0]['uri']+"' target='_blank'>" + forecast_alert_description + "</a>"
if forecast_alert_enabled == 1:
if "alerts" in data:
if len( data['alerts'][0]['description'] ) > forecast_alert_length:
forecast_alert_description = data['alerts'][0]['description'][:forecast_alert_length] + '...'
else:
forecast_alert_description = data['alerts'][0]['description']
# Final alert string
forecast_alert_text = "<strong>" + data['alerts'][0]['title'] + ":</strong> <a href='"+data['alerts'][0]['uri']+"' target='_blank'>" + forecast_alert_description + "</a>"

forecast_html_output = ""
forecast_updated = time.strftime( "%B %d, %Y, %-I:%M %p %Z", time.localtime( data["currently"]["time"] ) )
Expand Down
4 changes: 4 additions & 0 deletions skins/Belchertown/index.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@
jQuery("#wxicon").attr( "src", "$belchertown_root_url/images/" + data['currently']['icon'] + ".png" );
}

#if $Extras.has_key("forecast_alert_enabled") and $Extras.forecast_alert_enabled == '1'
// Weather Alerts
if ( data['alerts'] ) {
jQuery(".wx-stn-alert-text").html( "<strong>" + data['alerts'][0]['title'] + ":</strong> <a href='"+data['alerts'][0]['uri']+"' target='_blank'>" + data['alerts'][0]['description'].substring(0,$Extras.forecast_alert_length) + "...</a>" );
jQuery(".wx-stn-alert").show();
} else {
jQuery(".wx-stn-alert").hide();
}
#end if

// Current observation text
jQuery(".current-obs-text").html( data["currently"]["summary"] );
Expand Down Expand Up @@ -635,7 +637,9 @@
$social_html
#end if
<div class="clear"></div>
#if $Extras.has_key("forecast_alert_enabled") and $Extras.forecast_alert_enabled == '1'
<div class="wx-stn-alert"><i class="fa fa-exclamation-triangle"></i> <span class="wx-stn-alert-text">$forecast_alert_text</span></div><!--AJAX-->
#end if
</div>

<!-- First row with temperature, observation data and radar -->
Expand Down
1 change: 1 addition & 0 deletions skins/Belchertown/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
darksky_units = "auto"
darksky_lang = "en"
forecast_stale = 3540
forecast_alert_enabled = 0
forecast_alert_length = 75

# Earthquake defaults
Expand Down

0 comments on commit a725478

Please sign in to comment.