import datetime import time dataFileName = "data.csv" dateColumnIndex = 0 dataColumnIndex = 2 # temperature_DS18B20_outside metric = "sensor.weather" tags = "param=temperatureC location=outside id=DS18B20" def main(): with open(dataFileName, "rt") as fData: while True: row = fData.readline() if not row: break row = row.strip() row = row.split() dateTimeStamp = row[dateColumnIndex] value = row[dataColumnIndex] year = dateTimeStamp[0:4] month = dateTimeStamp[4:6] day = dateTimeStamp[6:8] hours = dateTimeStamp[8:10] minutes = dateTimeStamp[10:12] seconds = dateTimeStamp[12:] dateTime = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes), int(seconds)) unixTimestamp = int(time.mktime(dateTime.timetuple())) print(f'put {metric} {unixTimestamp} {value} {tags}') if __name__ == '__main__': main()