Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions Examples/pokemon-trainer/basic-write-writeoptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options
import pandas as pd
import numpy as np
import datetime



wco = write_client_options(write_options=SYNCHRONOUS)


with InfluxDBClient3(
token="",
host="eu-central-1-1.aws.cloud2.influxdata.com",
org="6a841c0c08328fb1",
database="pokemon-codex", write_client_options=wco, debug=True) as client:

now = datetime.datetime.now(datetime.timezone.utc)

data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1")\
.field("caught", "charizard")\
.field("level", 10).field("attack", 30)\
.field("defense", 40).field("hp", 200)\
.field("speed", 10)\
.field("type1", "fire").field("type2", "flying")\
.time(now)



try:
client.write(data)
except Exception as e:
print(f"Error writing point: {e}")

data = []
# Adding first point
data.append(
Point("caught")
.tag("trainer", "ash")
.tag("id", "0006")
.tag("num", "1")
.field("caught", "charizard")
.field("level", 10)
.field("attack", 30)
.field("defense", 40)
.field("hp", 200)
.field("speed", 10)
.field("type1", "fire")
.field("type2", "flying")
.time(now)
)

# Adding second point
data.append(
Point("caught")
.tag("trainer", "ash")
.tag("id", "0007")
.tag("num", "2")
.field("caught", "bulbasaur")
.field("level", 12)
.field("attack", 31)
.field("defense", 31)
.field("hp", 190)
.field("speed", 11)
.field("type1", "grass")
.field("type2", "poison")
.time(now)
)

# Adding third point
data.append(
Point("caught")
.tag("trainer", "ash")
.tag("id", "0008")
.tag("num", "3")
.field("caught", "squirtle")
.field("level", 13)
.field("attack", 29)
.field("defense", 40)
.field("hp", 180)
.field("speed", 13)
.field("type1", "water")
.field("type2", None)
.time(now)
)


try:
client.write(data)
except Exception as e:
print(f"Error writing point: {e}")


2 changes: 1 addition & 1 deletion influxdb_client_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
"""
self._org = org
self._database = database
self._write_client_options = write_client_options or {'write_options': SYNCHRONOUS}
self._write_client_options = write_client_options or write_client_options(write_options=SYNCHRONOUS)

# Extracting the hostname from URL if provided
parsed_url = urllib.parse.urlparse(host)
Expand Down