Skip to content

Commit 2e11916

Browse files
committed
fixed output of weather modules
1 parent 4980664 commit 2e11916

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

modules/nws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
county_list = 'https://alerts.weather.gov/cap/{0}.php?x=3'
138138
alerts = 'https://alerts.weather.gov/cap/wwaatmget.php?x={0}'
139139
zip_code_lookup = 'https://www.zip-codes.com/zip-code/{0}/zip-code-{0}.asp'
140-
nomsg = 'There are no active watches, warnings or advisories, for {0}.'
140+
nomsg = 'There are no active watches, warnings or advisories for {0}.'
141141
re_fips = re.compile(r'County FIPS:</.*?>(\S+)</td></tr>')
142142
re_state = re.compile(r'State:</span></td><td class="info"><a href="/state/\S\S.asp">\S\S \[([A-Za-z ]+)\]</a></td></tr>')
143143
re_city = re.compile(r'City:</span></td><td class="info"><a href="/city/\S+.asp">(.*)</a></td></tr>')

modules/weather.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,34 @@ def remove_dots(txt):
605605
if '..' not in txt:
606606
return txt
607607
else:
608-
txt = re.sub(r'\.\.', '.', txt)
608+
txt = re.sub(r'\.+', ' ', txt)
609609
return remove_dots(txt)
610610

611+
612+
def remove_spaces(x):
613+
if ' ' in x:
614+
x = x.replace(' ', ' ')
615+
return remove_spaces(x)
616+
else:
617+
return x
618+
619+
611620
def chomp_desc(txt):
612621
out = txt
613622
#print "original:", out
623+
p = re.compile(r'(?<=[\.\?!]\s)(\w+)')
624+
614625
def upper_repl(match):
615626
return match.group(1).upper()
627+
628+
def cap(match):
629+
return match.group().capitalize()
630+
616631
out = re.sub('([Tt])hunder(storm|shower)', r'\1\2', out)
617632
out = re.sub('with', 'w/', out)
618633
out = re.sub('and', '&', out)
634+
out = re.sub('during', 'in', out)
635+
out = re.sub('becoming', '', out)
619636
out = re.sub('occasionally', 'occ', out)
620637
out = re.sub('occasional', 'occ', out)
621638
out = re.sub('especially', 'esp.', out)
@@ -627,8 +644,16 @@ def upper_repl(match):
627644
out = re.sub('afternoon', 'PM', out)
628645
out = re.sub('in the', 'in', out)
629646
#out = re.sub(r'\.\.', ' ', out)
630-
out = remove_dots(out)
631647
out = re.sub('Then the (\S)', upper_repl, out)
648+
out = re.sub(r'(?i)(\b)(?:the|a)(\b)', r'\1\2', out)
649+
#out = re.sub(cap, '', out)
650+
651+
out = remove_dots(out)
652+
out = remove_spaces(out)
653+
654+
out = p.sub(cap, out)
655+
656+
out = out.strip()
632657
return out
633658

634659

@@ -703,7 +728,12 @@ def forecast(jenni, input):
703728
windspeedC = form % (float(day['windSpeed']) * 1.609344)
704729
windspeed = form % (day['windSpeed'])
705730
summary = day['summary']
706-
dotw_day = datetime.datetime.fromtimestamp(int(day['sunriseTime'])).weekday()
731+
#print("day:", str(day))
732+
day_ts = day['time']
733+
if "sunriseTime" in day:
734+
day_ts = int(day['sunriseTime'])
735+
736+
dotw_day = datetime.datetime.fromtimestamp(day_ts).weekday()
707737
dotw_day_pretty = u'\x0310\x02\x1F%s\x1F\x02\x03' % (dotw[dotw_day])
708738

709739
line = u'%s: \x02\x0304%sF (%sC)\x03\x02 / \x02\x0312%sF (%sC)\x03\x02, \x1FDew\x1F: %sF (%sC), \x1FWind\x1F: %smph (%skmh), %s | '
@@ -760,6 +790,7 @@ def forecast(jenni, input):
760790
jenni.say(second_output)
761791
forecast.commands = ['forecast', 'fct', 'fc']
762792
forecast.rate = 5
793+
forecast.priority = 'low'
763794

764795

765796
def forecastio_current_weather(jenni, input):
@@ -871,6 +902,7 @@ def forecastio_current_weather(jenni, input):
871902
jenni.say(output)
872903
forecastio_current_weather.commands = ['wxi-ft', 'wx-ft', 'weather-ft', 'weather', 'wx']
873904
forecastio_current_weather.rate = 5
905+
forecastio_current_weather.priority = 'high'
874906

875907

876908
def make_rh_C(temp, dewpoint):
@@ -988,6 +1020,7 @@ def weather_wunderground(jenni, input):
9881020

9891021
weather_wunderground.commands = ['wx-wg', 'weather-wg']
9901022
weather_wunderground.rate = 10
1023+
weather_wunderground.priority = 'high'
9911024

9921025

9931026
def preface_location(ci, reg='', cty=''):
@@ -1075,7 +1108,7 @@ def forecast_wg(jenni, input):
10751108
if not days_text[k + 1].endswith('.'):
10761109
days_text1_temp += '.'
10771110

1078-
temp = '\x02\x0310%s\x03\x02: %s / %s, \x1FCond\x1F: %s Eve: %s | ' % (day_of_week, highs, lows, days_text_temp, days_text1_temp)
1111+
temp = '\x02\x0310%s\x03\x02: %s / %s, AM: %s PM: %s | ' % (day_of_week, highs, lows, days_text_temp, days_text1_temp)
10791112

10801113
k += 2
10811114
if (k / 2.) <= 2:
@@ -1090,9 +1123,16 @@ def forecast_wg(jenni, input):
10901123
jenni.say(output_second)
10911124

10921125
forecast_wg.commands = ['forecast-wg']
1126+
forecast_wg.priority = 'low'
10931127
forecast_wg.rate = 5
10941128

10951129

1130+
def radar_us(jenni, input):
1131+
return jenni.say('https://radar.weather.gov/Conus/Loop/NatLoop.gif')
1132+
radar_us.commands = ['radar_us',]
1133+
radar_us.priority = 'low'
1134+
1135+
10961136

10971137
if __name__ == '__main__':
10981138
print __doc__.strip()

0 commit comments

Comments
 (0)