[DEBUG] update upload
This commit is contained in:
parent
1d0e8899d5
commit
aa9331ab05
@ -10,4 +10,5 @@
|
||||
from .exception import KaranageException
|
||||
from .connection import KaranageConnection
|
||||
from .state import StateSystem, KaranageState
|
||||
from .log import KaranageLog
|
||||
from .log import KaranageLog, GroupLogElement
|
||||
|
||||
|
@ -10,12 +10,13 @@
|
||||
import enum
|
||||
import requests
|
||||
import json
|
||||
from typing import Dict, Optional
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, Optional, List
|
||||
from .connection import KaranageConnection
|
||||
from .exception import KaranageException
|
||||
|
||||
class GroupLogElement:
|
||||
def __init__(self, id: int, time: Datetime:None, data: str):
|
||||
def __init__(self, id: int, data: str, time: datetime = None):
|
||||
self.id = id
|
||||
self.time = time
|
||||
self.data = data
|
||||
@ -35,7 +36,7 @@ class KaranageLog:
|
||||
return self.connection.get_url(self.service)
|
||||
return f"{self.connection.get_url(self.service)}/{self.system}"
|
||||
|
||||
def send(self, data: Dict, id: int = None, uuid_group: int= None, time: Datetime = None) -> None:
|
||||
def send(self, data: Dict, id: Optional[int] = None, uuid_group: Optional[int] = None, time: Optional[datetime] = None) -> None:
|
||||
"""Send a message to the server.
|
||||
:param data: Data to send to the server
|
||||
:param id: Local internal ID
|
||||
@ -48,7 +49,7 @@ class KaranageLog:
|
||||
if uuid_group is not None:
|
||||
param["uuid"] = uuid_group
|
||||
if time is not None:
|
||||
param["time"] = id
|
||||
param["time"] = time.astimezone(timezone.utc).isoformat()
|
||||
header = self.connection.get_header()
|
||||
try:
|
||||
ret = requests.post(self.get_url(), json=data, headers=header, params=param)
|
||||
@ -57,11 +58,20 @@ class KaranageLog:
|
||||
if not 200 <= ret.status_code <= 299:
|
||||
raise KaranageException(f"Fail send message: {self.get_url()}", ret.status_code, ret.content.decode("utf-8"))
|
||||
|
||||
def send_multiple(self, data: List[GroupLogElement], uuid_group: int= None) -> None:
|
||||
def send_multiple(self, data_input: List[GroupLogElement], uuid_group: Optional[int]= None) -> None:
|
||||
"""Send multiple log message to the server.
|
||||
:param data: Data to send to the server
|
||||
:param uuid_group: local internal group UUID
|
||||
"""
|
||||
# Convert:
|
||||
data = []
|
||||
for elem in data_input:
|
||||
data.append({
|
||||
"id": elem.id,
|
||||
"time": elem.time.astimezone(timezone.utc).isoformat(),
|
||||
"data": elem.data,
|
||||
})
|
||||
|
||||
param = {}
|
||||
if uuid_group is not None:
|
||||
param["uuid"] = uuid_group
|
||||
|
Loading…
Reference in New Issue
Block a user