-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_importer.py
44 lines (34 loc) · 1.16 KB
/
csv_importer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python
import argparse
import csv
import time
import sqlite3
from core import SensorReadingsDataStore
def main():
"""
Example on how to import CSV into Sqlite3 database. In this case, the data comes
from a csv file generated from dummy_data.py
Expected order of columns:
[0] = Sensor ID
[1] = Sensor Type
[2] = Unix timestamp
[3] = Value
[4] = Value Type
[5] = Value Unit
"""
parser = argparse.ArgumentParser(description='Import CSV data into sensor readings database')
parser.add_argument('-d', '--db', help='Sqlite3 database file', default='data/artf_sensors_demo.sqlite3')
parser.add_argument('-c', '--csv', help='CSV Filename', default='dummy_data.csv')
args = parser.parse_args()
db = args.db
csv_filename = args.csv
readings = []
with open(csv_filename, 'r') as csvfile:
data = csv.reader(csvfile)
for line in data:
readings.append([line[0], line[1], int(line[2]), int(line[3]), line[4],line[5]])
logger = SensorReadingsDataStore(db)
logger.setup()
logger.store_readings(readings)
if __name__ == '__main__':
main()