Exemplo n.º 1
0
def filenameFilter(filename: str):
    return re.compile(FILE_PATTERN).match(filename) \
        and utils.getStationCodeFromHistalp(re.compile(FILE_PATTERN).search(filename).group(1)) != None \
        and re.compile(FILE_PATTERN).search(filename).group(2) in PHENOMENONS
Exemplo n.º 2
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


def sendToSos(xml: str):
    try:
        log.info("Inserting observation...")
        request = urllib.request.Request(utils.POX_URL, xml.encode("UTF-8"), utils.POST_HEADER)
        resp_handle = urllib.request.urlopen(request)
        response = resp_handle.read().decode(resp_handle.headers.get_content_charset())
        log.info(response)
        resp_handle.close()
    except Exception as e:
        log.error("Error code: ", e)
        traceback.print_exc()


for (dirpath, dirnames, filenames) in os.walk(HISTALP_FILE_PATH):
    for filename in filter(filenameFilter, filenames):
        log.info("Reading {}".format(filename))
        station = utils.getStationCodeFromHistalp(re.compile(FILE_PATTERN).search(filename).group(1))
        pheno = re.compile(FILE_PATTERN).search(filename).group(2)
        log.debug("Station: {0}, Phenomenon: {1}".format(station, pheno))
        with open(HISTALP_FILE_PATH + filename, newline='') as csvfile:
            fileReader = csv.reader(csvfile, delimiter=';')
            for row in filter(rowFilter, fileReader):
                parseRow(row, station, pheno)