-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinflux.py
26 lines (22 loc) · 812 Bytes
/
influx.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
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.domain.write_precision import *
from DataPoint import *
from datetime import datetime
from time import time
def writeInfluxDBPoint(influxDbClient, bucket, dataPoint):
timestamp = dataPoint.date
with influxDbClient.write_api() as write_api:
dict_structure = {
"measurement": "nasdaq",
"tags": {
"symbol": dataPoint.symbol,
},
"fields": {
"price": dataPoint.price,
},
"time": timestamp
}
print(f"dataPoint: {dict_structure}")
point = Point.from_dict(dict_structure, WritePrecision.MS)
write_api.write(bucket=bucket, record=point)