def createInsertSensorXml(obs): featureXml = utils.XML_FEATURE.format(obs[0].lower(), utils.featureId(obs[0]), obs[0], utils.STATIONS[obs[0]][1]) timePositionXml = utils.XML_TIME_POSITION.format( obs[1].strftime("%Y-%m-%dT23:59:59.000+00:00")) procedureXref = utils.procedureXref("gsod") observations = [ ("http://vocab.example.com/phenomenon/TemperatureMean", "°C"), ("http://vocab.example.com/phenomenon/TemperatureMax", "°C"), ("http://vocab.example.com/phenomenon/TemperatureMin", "°C"), ("http://vocab.example.com/phenomenon/WindspeedMean", "kn"), ("http://vocab.example.com/phenomenon/WindspeedMax", "kn"), ("http://vocab.example.com/phenomenon/WindspeedGust", "kn"), ("http://vocab.example.com/phenomenon/Precipitation", "mm"), ] result = [] for i in range(2, len(obs)): if obs[i] not in [9999.9, 999.9, 99.99]: xmlObsProp = utils.XML_OBSERVED_PROPERTY.format(observations[i - 2][0]) xmlResult = utils.XML_RESULT.format(observations[i - 2][1], obs[i]) content = timePositionXml + procedureXref + xmlObsProp + featureXml + xmlResult insertObsXml = utils.XML_INSERT_OBS.format( utils.offeringId("gsod"), content) log.debug(insertObsXml) result.append(insertObsXml) return result
def createInsertSensorXml(obs): featureXml = utils.XML_FEATURE.format(obs[0].lower(), utils.featureId(obs[0]), obs[0], utils.STATIONS[obs[0]][1]) timePositionXml = utils.XML_TIME_POSITION.format(obs[1].strftime("%Y-%m-%dT23:59:59.000+00:00")) procedureXref = utils.procedureXref("gsod") observations = [ ("http://vocab.example.com/phenomenon/TemperatureMean", "°C"), ("http://vocab.example.com/phenomenon/TemperatureMax", "°C"), ("http://vocab.example.com/phenomenon/TemperatureMin", "°C"), ("http://vocab.example.com/phenomenon/WindspeedMean", "kn"), ("http://vocab.example.com/phenomenon/WindspeedMax", "kn"), ("http://vocab.example.com/phenomenon/WindspeedGust", "kn"), ("http://vocab.example.com/phenomenon/Precipitation", "mm"), ] result = [] for i in range(2, len(obs)): if obs[i] not in [9999.9, 999.9, 99.99]: xmlObsProp = utils.XML_OBSERVED_PROPERTY.format(observations[i - 2][0]) xmlResult = utils.XML_RESULT.format(observations[i - 2][1], obs[i]) content = timePositionXml + procedureXref + xmlObsProp + featureXml + xmlResult insertObsXml = utils.XML_INSERT_OBS.format(utils.offeringId("gsod"), content) log.debug(insertObsXml) result.append(insertObsXml) return result
def createXml(dt, value, station, pheno): log.info("Create XML for: {0}, {1}, {2}, {3}".format(dt, value, station, pheno)) featureXml = utils.XML_FEATURE.format(station.lower(), utils.featureId(station), station, utils.STATIONS[station][1]) timePositionXml = utils.XML_TIME_POSITION.format(dt.strftime("%Y-%m-%dT00:00:00.000+00:00")) procedureXref = utils.procedureXref("histalp") xmlObsProp = utils.XML_OBSERVED_PROPERTY.format(PHENOMENONS[pheno][0]) xmlResult = utils.XML_RESULT.format(PHENOMENONS[pheno][1], value) content = timePositionXml + procedureXref + xmlObsProp + featureXml + xmlResult insertObsXml = utils.XML_INSERT_OBS.format(utils.offeringId("histalp"), content) log.debug(insertObsXml) return insertObsXml
obs.wind_dir.string() if obs.wind_dir else "variable", obs.wind_speed.string("kt") if obs.wind_speed else "None" ) ) # these are the parts of the METAR we're interested in observations = [ ("http://sweet.jpl.nasa.gov/2.3/propTemperature.owl#Temperature", "°C", obs.temp.value('C') if obs.temp else None), ("http://sweet.jpl.nasa.gov/2.3/propTemperature.owl#DewPoint", "°C", obs.dewpt.value('C') if obs.dewpt else None), ("http://sweet.jpl.nasa.gov/2.3/phenAtmoPressure.owl#Barometric", "hPa", obs.press.value('hPa') if obs.press else None), ("http://sweet.jpl.nasa.gov/2.3/propSpeed.owl#WindSpeed", "kn", obs.wind_speed.value('kt') if obs.wind_speed else None), ("http://vocab.example.com/phenomenon/WindDirection", "deg", obs.wind_dir.value() if obs.wind_dir else None) ] # create XML strings featureXml = utils.XML_FEATURE.format(obs.station_id.lower(), utils.featureId(obs.station_id), obs.station_id, utils.STATIONS[obs.station_id][1]) timePositionXml = utils.XML_TIME_POSITION.format(obs.time.strftime("%Y-%m-%dT%H:%M:00.000+00:00")) procedureXref = utils.procedureXref("metar") # loop over all interesting observations and push them into the SOS for observation in observations: if (observation[2]): xmlObsProp = utils.XML_OBSERVED_PROPERTY.format(observation[0]) if (observation[1] == ""): xmlResult = utils.XML_RESULT_TEXT.format(observation[1]) else: xmlResult = utils.XML_RESULT.format(observation[1], observation[2]) content = timePositionXml + procedureXref + xmlObsProp + featureXml + xmlResult insertObsXml = utils.XML_INSERT_OBS.format(utils.offeringId("metar"), content)
observations = [ ("http://sweet.jpl.nasa.gov/2.3/propTemperature.owl#Temperature", "°C", obs.temp.value('C') if obs.temp else None), ("http://sweet.jpl.nasa.gov/2.3/propTemperature.owl#DewPoint", "°C", obs.dewpt.value('C') if obs.dewpt else None), ("http://sweet.jpl.nasa.gov/2.3/phenAtmoPressure.owl#Barometric", "hPa", obs.press.value('hPa') if obs.press else None), ("http://sweet.jpl.nasa.gov/2.3/propSpeed.owl#WindSpeed", "kn", obs.wind_speed.value('kt') if obs.wind_speed else None), ("http://vocab.example.com/phenomenon/WindDirection", "deg", obs.wind_dir.value() if obs.wind_dir else None) ] # create XML strings featureXml = utils.XML_FEATURE.format( obs.station_id.lower(), utils.featureId(obs.station_id), obs.station_id, utils.STATIONS[obs.station_id][1]) timePositionXml = utils.XML_TIME_POSITION.format( obs.time.strftime("%Y-%m-%dT%H:%M:00.000+00:00")) procedureXref = utils.procedureXref("metar") # loop over all interesting observations and push them into the SOS for observation in observations: if (observation[2]): xmlObsProp = utils.XML_OBSERVED_PROPERTY.format(observation[0]) if (observation[1] == ""): xmlResult = utils.XML_RESULT_TEXT.format(observation[1]) else: xmlResult = utils.XML_RESULT.format( observation[1], observation[2])
elif (proc == "histalp"): xmlTime = "<!-- NO TEMP FILTER -->" # xmlTime = XML_TEMP_FILTER.format( # "1976-01-01T00:00:00.000+00:00", # "2015-08-27T00:00:00.000+00:00" # ) else: xmlTime = XML_TEMP_FILTER.format( # (datetime.utcnow() - timedelta(days=1)).strftime("%Y-%m-%dT%H:%M:00.000+00:00"), # datetime.utcnow().strftime("%Y-%m-%dT%H:%M:00.000+00:00") "2015-08-26T00:00:00.000+00:00", "2015-08-27T00:00:00.000+00:00") # replacing the blanks in XML_GET_OBS xmlRequest = XML_GET_OBS.format( utils.featureId(stationCode), utils.procedureId(proc), xmlTime, ) log.debug(xmlRequest) # sending the request request = urllib.request.Request(utils.POX_URL, xmlRequest.encode("UTF-8"), utils.POST_HEADER) # getting response resp_handle = urllib.request.urlopen(request) response = resp_handle.read().decode( resp_handle.headers.get_content_charset()) log.debug(response)
xmlTime = "<!-- NO TEMP FILTER -->" # xmlTime = XML_TEMP_FILTER.format( # "1976-01-01T00:00:00.000+00:00", # "2015-08-27T00:00:00.000+00:00" # ) else: xmlTime = XML_TEMP_FILTER.format( # (datetime.utcnow() - timedelta(days=1)).strftime("%Y-%m-%dT%H:%M:00.000+00:00"), # datetime.utcnow().strftime("%Y-%m-%dT%H:%M:00.000+00:00") "2015-08-26T00:00:00.000+00:00", "2015-08-27T00:00:00.000+00:00" ) # replacing the blanks in XML_GET_OBS xmlRequest = XML_GET_OBS.format( utils.featureId(stationCode), utils.procedureId(proc), xmlTime, ) log.debug(xmlRequest) # sending the request request = urllib.request.Request( utils.POX_URL, xmlRequest.encode("UTF-8"), utils.POST_HEADER ) # getting response resp_handle = urllib.request.urlopen(request)