def post_condition(self, request): app_config = appconfig.load_settings() config = app_config["locations"][request.location] c = condition.Condition(location=request.location, station=request.station, json=request.json) if c: memcache.set(key=c.location, value=c, namespace="conditions") # if it's raining, update the last rain datetime in the cache if c.is_raining: wxutils.update_last_rain(c.location, c.date) wxutils.update_high_low_averages(condition=c) # self.store_condition(request) if config and "wunderground" in config: wu_config = config["wunderground"] if "conditions" in wu_config and wu_config["conditions"]: wu.post(condition=c, station=wu_config["station"], password=wu_config["password"]) return message_types.VoidMessage()
def upload_archive(self, request): # logging.info(request.json) app_config = appconfig.load_settings() config = app_config['locations'][request.location] logging.info('archive record date: ' + str(parser.parse(request.date))) #archive.DbArchive(location=request.location, # date=parser.parse(request.date), json=request.json, station=request.station).put() archive_record = json_to_dbarchive(request.location, request.date, request.station, request.json) # check for dups (location + date)? # populate all fields # store the record if archive_record: archive.ArchiveFactory.put(archive_record) # update last rain if archive_record.rainfall > 0: wxutils.update_last_rain(archive_record.location, archive_record.date) if config and 'wunderground' in config: wu_config = config['wunderground'] if 'archives' in wu_config and wu_config['archives']: wu.post(archive=archive_record, station=wu_config['station'], password=wu_config['password']) wxutils.update_high_low_averages(archive=archive_record) return message_types.VoidMessage()
def get(self): if len(self.request.get("location")): location = self.request.get("location") else: location = '01915' station_settings = appconfig.load_settings(location) if station_settings: if 'tz' in station_settings: localtz = pytz.timezone(station_settings['tz']) else: localtz = pytz.timezone('America/New_York') if 'forecast_location' in station_settings: forecast_location = station_settings['forecast_location'] else: forecast_location = 'KBVY' if 'conditions_location' in station_settings: conditions_location = station_settings['conditions_location'] else: conditions_location = 'KBVY' else: location = "01915" self.response.out.write('<html><head><meta HTTP-EQUIV="Refresh" CONTENT="3">') self.response.out.write("""<script type="text/javascript">""" """var _gaq = _gaq || [];""" """_gaq.push(['_setAccount', 'UA-11819295-3']);""" """_gaq.push(['_trackPageview']);""" """(function() {""" """var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;""" """ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';""" """var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);""" """})();""") self.response.out.write('</script></head><body>') if len(self.request.get("metric")): metric = True else: metric = False cond = condition.ConditionFactory.find(location, metric) if cond: self.response.out.write("current date: " + datetime.datetime.strftime(datetime.datetime.now(tz=localtz),"%Y-%m-%d %H:%M:%S%z") + "<br>") self.response.out.write("Conditions for: " + location + "<br>") self.response.out.write("station type: " + cond.station + "<br>") self.response.out.write('conditions as of: ' + str(cond.date) + '<br>') self.response.out.write('temp: ' + str(cond.outside_temp) + '<br>') self.response.out.write('feels like: ' + str(cond.apparent_temp) + '<br>') self.response.out.write('dewpoint: ' + str(cond.dewpoint) + '<br>') if not cond.wind_speed: self.response.out.write('wind: calm <br>') else: self.response.out.write('wind: ' + str(cond.wind_speed) + ' from ' + wind.deg_to_short_str(cond.wind_direction) + '<br>') self.response.out.write('ten min wind avg: ' + str(cond.ten_min_wind_speed) + '<br>') self.response.out.write('pressure: ' + str(cond.pressure) + ' - ' + cond.pressure_trend + '<br>') self.response.out.write('humidity: ' + str(cond.outside_humidity) + '<br>') if cond.is_raining: self.response.out.write('raining at ' + str(cond.rain_rate) + ' inches per hour' + '<br>') self.response.out.write('this rain event: ' + str(cond.storm_rain) + '<br>') self.response.out.write('rain today: ' + str(cond.day_rain) + ' inches' + '<br>') self.response.out.write('rain this month: ' + str(cond.month_rain) + ' inches' + '<br>') self.response.out.write('rain this year: ' + str(cond.year_rain) + ' inches' + '<br>') if cond.solar_radiation <> 32767: self.response.out.write('solar radiation: ' + str(cond.solar_radiation) + ' watts per square meter' + '<br>') self.response.out.write('sunrise: ' + str(cond.sunrise) + '<br>') self.response.out.write('sunset: ' + str(cond.sunset) + '<br>') else: self.response.out.write('no conditions found' + "<br>") logging.info('no conditions found') self.response.out.write('latest archive record: ' + str(archive.ArchiveFactory.find_latest_datetime(location)) + '<br>') self.response.out.write('last rain: ' + str(wxutils.last_rain(location)) + '<br>') conditions = ConditionsFactory.get(forecast_location) if conditions: self.response.out.write('\nConditions ') self.response.out.write('Retrieved: ' + conditions.retrieved.strftime("%Y-%m-%d %H:%M:%S %z") +'<br>') self.response.out.write(conditions.as_of + '<br>') self.response.out.write('Weather: ' + conditions.weather + '<br>') self.response.out.write('Visibility: ' + conditions.visibility + ' miles<br>') forecast = ForecastFactory.get(conditions_location) if forecast: self.response.out.write('Forecast<br>') self.response.out.write('Retrieved: ' + forecast.retrieved.strftime("%Y-%m-%d %H:%M:%S %z") +'<br>') self.response.out.write('As of ') self.response.out.write(forecast.as_of + '<br>') for day in forecast.days: self.response.out.write(day.dayname + ': ' + day.forecast + '<br>') self.response.out.write('</body></html>')