Skip to content
Snippets Groups Projects
Commit d0af6318 authored by William Roberts's avatar William Roberts
Browse files

Add try except clause back in

parent bae47fc5
No related branches found
No related tags found
No related merge requests found
...@@ -185,68 +185,72 @@ def main(): ...@@ -185,68 +185,72 @@ def main():
src = open(args.src, "r") src = open(args.src, "r")
record_gen = read_frames(src, tail=args.tail) record_gen = read_frames(src, tail=args.tail)
influx_gen = convert_to_influx_frame(record_gen, symbols, args.debug) try:
influx_gen = influxdb.grouper(influx_gen, args.bulk) influx_gen = convert_to_influx_frame(record_gen, symbols, args.debug)
updater = Updater() influx_gen = influxdb.grouper(influx_gen, args.bulk)
for record in influx_gen: updater = Updater()
# lines = influxdb.frame_records(record, **station_tags) for record in influx_gen:
# influxdb.insert(lines, host=args.host, port=args.port, dbname=args.dbname) # lines = influxdb.frame_records(record, **station_tags)
# Record is in a list of size 1, but want just the record. # influxdb.insert(lines, host=args.host, port=args.port, dbname=args.dbname)
avg = updater.rolling_average(record[0]) # Record is in a list of size 1, but want just the record.
# Once every 5 minutes: 0 through 295 seconds inclusive. avg = updater.rolling_average(record[0])
if avg is not None: # Once every 5 minutes: 0 through 295 seconds inclusive.
# For timestamp, want YYYY-MM-DD+hh:mm:ss of last dataset that was averaged, rounded up to nearest minute. if avg is not None:
timestamp = avg.index[-1].round('1T').isoformat('+') # For timestamp, want YYYY-MM-DD+hh:mm:ss of last dataset that was averaged, rounded up to nearest minute.
wind_dir = avg['wind_dir'][-1] timestamp = avg.index[-1].round('1T').isoformat('+')
wind_dir_2m = avg['wind_dir_2m'][-1] wind_dir = avg['wind_dir'][-1]
# Converts from m/s to mph. wind_dir_2m = avg['wind_dir_2m'][-1]
wind_speed = avg['wind_speed'][-1] * 2.23694 # Converts from m/s to mph.
wind_speed_2m = avg['wind_speed_2m'][-1] * 2.23694 wind_speed = avg['wind_speed'][-1] * 2.23694
cur_gust = avg['cur_gust'][-1] * 2.23694 wind_speed_2m = avg['wind_speed_2m'][-1] * 2.23694
gust_10m = avg['gust_10m'][-1] * 2.23694 cur_gust = avg['cur_gust'][-1] * 2.23694
rel_hum = avg['rel_hum'][-1] gust_10m = avg['gust_10m'][-1] * 2.23694
# Converts degrees Celsius to degrees Fahrenheit rel_hum = avg['rel_hum'][-1]
air_temp = avg['air_temp'][-1] * 9. / 5. + 32. # Converts degrees Celsius to degrees Fahrenheit
# hpa to barometric pressure inches air_temp = avg['air_temp'][-1] * 9. / 5. + 32.
pressure = avg['pressure'][-1] * 0.02952998016471232 # hpa to barometric pressure inches
# degrees Celcus to degrees Fahrenheit. pressure = avg['pressure'][-1] * 0.02952998016471232
dewpoint = avg['dewpoint'][-1] * 9. / 5. + 32. # degrees Celcus to degrees Fahrenheit.
solar_flux = avg['solar_flux'][-1] dewpoint = avg['dewpoint'][-1] * 9. / 5. + 32.
precip = avg['precip'][-1] solar_flux = avg['solar_flux'][-1]
accum_precip = avg['accum_precip'][-1] precip = avg['precip'][-1]
url = ('http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?' accum_precip = avg['accum_precip'][-1]
'ID={wu_id}&' url = ('http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?'
'PASSWORD={wu_pw}&' 'ID={wu_id}&'
'action=updateraw&' 'PASSWORD={wu_pw}&'
'dateutc={timestamp}&' 'action=updateraw&'
'winddir={wind_dir}&' 'dateutc={timestamp}&'
'winddir_avg2m={wind_dir_2m}&' 'winddir={wind_dir}&'
'windspeedmph={wind_speed}&' 'winddir_avg2m={wind_dir_2m}&'
'windspdmph_avg2m={wind_speed_2m}&' 'windspeedmph={wind_speed}&'
'windgustmph={cur_gust}&' 'windspdmph_avg2m={wind_speed_2m}&'
'windgustmph_10m={gust_10m}&' 'windgustmph={cur_gust}&'
'humidity={rel_hum}&' 'windgustmph_10m={gust_10m}&'
'tempf={air_temp}&' 'humidity={rel_hum}&'
'baromin={pressure}&' 'tempf={air_temp}&'
'dewptf={dewpoint}&' 'baromin={pressure}&'
'solarradiation={solar_flux}&' 'dewptf={dewpoint}&'
'rainin={precip}&' 'solarradiation={solar_flux}&'
'dailyrainin={accum_precip}&' 'rainin={precip}&'
'softwaretype=SSEC-RIG').format(wu_id=args.wu_id, wu_pw=wu_pw, 'dailyrainin={accum_precip}&'
timestamp=timestamp, wind_dir=wind_dir, wind_dir_2m=wind_dir_2m, 'softwaretype=SSEC-RIG').format(wu_id=args.wu_id, wu_pw=wu_pw,
wind_speed=wind_speed, wind_speed_2m=wind_speed_2m, timestamp=timestamp, wind_dir=wind_dir, wind_dir_2m=wind_dir_2m,
cur_gust=cur_gust, gust_10m=gust_10m, rel_hum=rel_hum, wind_speed=wind_speed, wind_speed_2m=wind_speed_2m,
air_temp=air_temp, pressure=pressure, dewpoint=dewpoint, cur_gust=cur_gust, gust_10m=gust_10m, rel_hum=rel_hum,
solar_flux=solar_flux, precip=precip, accum_precip=accum_precip) air_temp=air_temp, pressure=pressure, dewpoint=dewpoint,
print(url) solar_flux=solar_flux, precip=precip, accum_precip=accum_precip)
# if wu_pw and args.ldmp: print(url)
# # TODO: CHECK FOR SUCCESS RESPONSE PING AFTER SENDING. # if wu_pw and args.ldmp:
# resp = requests.post(url) # # TODO: CHECK FOR SUCCESS RESPONSE PING AFTER SENDING.
# if resp != 'success': # resp = requests.post(url)
# raise ValueError('Data not received.') # if resp != 'success':
# raise ValueError('Data not received.')
if args.sleep_interval:
time.sleep(args.sleep_interval) if args.sleep_interval:
time.sleep(args.sleep_interval)
except (RuntimeError, ValueError, KeyError, requests.RequestException):
if hasattr(record_gen, 'close'):
record_gen.close()
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment