0
0

More than 1 year has passed since last update.

InfluxDB v1.8: python3 でデータの挿入

Posted at

次のページを参考にしました。
データ投入処理

Ubuntu 22.10 でのライブラリーのインストール

sudo apt install python3-influxdb

プログラム

influxdb_insert.py
#! /usr/bin/python
#
#	influxdb_insert.py
#
#						Dec/07/2022
# ------------------------------------------------------------------
import sys
import time
from influxdb import InfluxDBClient

# ------------------------------------------------------------------
def insert_proc(temperature_in):
	import_array = [
	{
	"fields" : {
		"IDX" : 1,
		"temperature" : temperature_in,
	},
	"measurement" : "Data"
	}
	]

	client.write_points(import_array)
#
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")

client = InfluxDBClient('example.com', 8086,"","", 'example')

dbs = client.get_list_database()
sample_db = {'name' : 'example'}
if sample_db not in dbs:
	client.create_database('example')

temperatures=[20.3,21.4,22.5,23.6,24.2]

for value in temperatures:
	print(value)
	insert_proc(value)
#
	time.sleep(1.0)
#
sys.stderr.write("*** 終了 ***\n")	
# ------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0