def getNewSnowFallForResort(resort) : snowfallEntry = {} try : weatherReportPage = resort['url'] soup = xmlHelper.createSoup(weatherReportPage) newSnow = -1 lastUpdated = "" #sampleCommand = 'xmlHelper.searchContentForTag("Summit","Last 24 hrs:","lh26\">", "</span", str(soup), 0)' exec "newSnow = " + resort['newSnowCommand'] exec "lastUpdated = " + resort['lastUpdatedCommand'] snowFallDate = datetime.date.today() - datetime.timedelta(days=1) snowfallEntry = {} snowfallEntry['resort'] = resort['id'] snowfallEntry['snowfall'] = filter(lambda x: x.isdigit(), newSnow[0]) snowfallEntry['updated_time'] = cleanInput(lastUpdated) snowfallEntry['date'] = str(snowFallDate) return snowfallEntry except : print "ERROR on resort: " + resort['name'] + ": " + str(sys.exc_info()[0]) return None
def getWeather(resort, db) : print "getting weather for " + resort['snowforecast_id'] url = sfWeatherUrl + resort['snowforecast_id'] + sfPostUrl soup = xmlHelper.createSoup(url) row = {} #print xmlHelper.getSnowForecastTag("mid", "dayname", soupStr) row['resort'] = resort['id'] row['reported_time'] = xmlHelper.getSnowForecastTag("hash", "issued", soup) #row['resort'] = resort for p in soup.findAll('period') : forecastTimestamp = xmlHelper.getSnowForecastTag("period", "tstampstart", p) forecastDate = datetime.datetime.fromtimestamp(int(forecastTimestamp)) row['date'] = str(forecastDate) row['forecast_time'] = xmlHelper.getSnowForecastTag("period", "ename", p).replace("-<br>","") row['freezing_level'] = xmlHelper.getSnowForecastTag("period", "flevel", p) row['summary'] = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "pphrase", p) row['low_temp'] = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "min", p) row['high_temp'] = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "max", p) row['wind'] = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "pwind", p) # Parse wind symbol data from something like windSW35metric.gif to SW wsymbol = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "pwsymbol", p) wsymbol = wsymbol.replace(SNOW_FORECAST_WIND_SYMBOL_PRE, "").replace(SNOW_FORECAST_WIND_SYMBOL_POST, "") wsymbol = wsymbol.replace(row['wind'], "") row['wind_dir'] = wsymbol snow_forecast = xmlHelper.getSnowForecastTag(FORECAST_LOCATION, "psnow", p) if snow_forecast == "-" : snow_forecast = 0 row['snow_forecast'] = snow_forecast queryString = dbHelper.createInsertStatement(row, TABLE_NAME) #print queryString db.query(queryString)