Adding Json Data from Python to Influxdb

influxdata
time-series
influxdb
#1

Hi I m new to influx db . i do had studied documentation and view some youtube videos but not yet not understood the usage.

My Question to all you mentors is how to i store data from Json format in influx db from python
my Json format
{ “Stock”: “AAPL”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
{ “Stock”: “GE”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
{ “Stock”: “GS”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
{ “Stock”: “BOM”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
{ “Stock”: “XOM”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
i would like to store this one minute data into influx stock_tick Data
any kind of help will be greatly appreciated… thanks in advance

I had created database :

Create database tickdata
use tickdata

Measurement:
Exchange = “DOW”

Tags:
StockName= “GE"
StockType =” FUT" /“EQ”

Fields:
open
high
low
close
volume
open interest

TimeStamp:
09:00:01

#3

If I am understanding you correctly, you just need to convert the JSON to InfluxDB Line Protocol in your script and output that format. You can then run that script via Telegraf to send it to InfluxDB.

#4

#!/usr/bin/env python

from influxdb import InfluxDBClient

data = [
{
“measurement”: MEASUREMENT,
“tags”: {
TAGS
},
“time”: str(datetime.datetime.now()),
“fields”: {
FIELDS
}
}
]

client = InfluxDBClient(host='INFLUXHOST, port=INFLUXPORT, database=DBNAME)
client.write_points(data)

(just ident the lines as python wise)

#5

I know thread is old but since I faced the same issue, here’s my solution:
I transformed the dicts to strings. So
{ “Stock”: “AAPL”,“TimeStamp”:10:00:00,“Open”: 150,“High”:154,“Low”:147,“Close”:141,“Volume”:3000}
becomes:
Stock=AAPL,Timestamp=10:00,Open=150,High=154,Low=147,Close=141,Volume=3000
then created a list of strings
and finally forged influxdb-fiendly string from the list with:
new-data = “\n”.join(mylist)
and then with python’s requst (for example) just added as parameter data=mylit and voila, multipoints written.