def processWeatherFile()

in noaa/_tools/process.py [0:0]


def processWeatherFile(weatherDataFile, stationsMap):
    with open(weatherDataFile, 'r') as file:
        csvreader = csv.reader(file, delimiter=',', quotechar='"')
        currentStationDoc = None
        stationDocsProcessed = 0
        for row in csvreader:
            station = stationsMap[row[0]]
            date = datetime.strptime(row[1], '%Y%m%d')
            elementType = row[2]
            elementValue = row[3]
            if currentStationDoc == None:
                currentStationDoc = {
                    'station': station,
                    'date': date,
                    elementType: elementValue
                }
            elif currentStationDoc['station'] != station or currentStationDoc['date'] != date:
                yield processWeatherDoc(currentStationDoc)
                stationDocsProcessed = stationDocsProcessed + 1
                currentStationDoc = {
                    'station': station,
                    'date': date,
                    elementType: elementValue
                }
            else:
                currentStationDoc[elementType] = elementValue