Last active
January 30, 2018 13:05
-
-
Save AntoineToubhans/9597a26f65d876fb639f32d24dc6180a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongots | |
from datetime import datetime | |
from csv import DictReader | |
temperature_collection = mongots.MongoTSClient().ClimaticDataDb.temperatures | |
with open('./weather_data.csv') as file: | |
reader = DictReader(file, delimiter=';') | |
failed = 0 | |
for idx, row in enumerate(reader): | |
try: | |
dt = datetime.strptime(row['datetime'], '%Y-%m-%d %H:%M:%S') | |
city = row['city'] | |
temperature = float(row['temperature']) | |
temperature_collection.insert_one(temperature, dt, tags={'city': city}) | |
except: | |
failed += 1 | |
if (idx + 1) % 10000 == 0: | |
print(f'{idx+1} row inserted ({failed} failed)', flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment