Skip to content

Instantly share code, notes, and snippets.

@AntoineToubhans
Last active January 30, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoineToubhans/9597a26f65d876fb639f32d24dc6180a to your computer and use it in GitHub Desktop.
Save AntoineToubhans/9597a26f65d876fb639f32d24dc6180a to your computer and use it in GitHub Desktop.
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