-
Notifications
You must be signed in to change notification settings - Fork 0
Python
PiotrFerenc edited this page May 14, 2024
·
1 revision
import json
import asyncio
import aiohttp
class Parameters:
def __init__(self, console_text):
self.ConsoleText = console_text
def to_dict(self):
return {"ConsoleText": self.ConsoleText}
class TaskItem:
def __init__(self, sequence, name, action):
self.Sequence = sequence
self.Name = name
self.Action = action
def to_dict(self):
return {"Sequence": self.Sequence, "Name": self.Name, "Action": self.Action}
class RequestPayload:
def __init__(self, parameters, tasks):
self.Parameters = parameters
self.Tasks = tasks
def to_dict(self):
return {
"Parameters": self.Parameters.to_dict(),
"Tasks": [task.to_dict() for task in self.Tasks]
}
async def main():
url = "http://localhost:5000/execute"
payload = RequestPayload(
Parameters("hallo word"),
[TaskItem(1, "log", "console")]
)
json_content = json.dumps(payload.to_dict())
headers = {'Content-Type': 'application/json'}
async with aiohttp.ClientSession() as session:
async with session.post(url, data=json_content, headers=headers) as response:
if response.status == 200:
response_content = await response.text()
print("Response:", response_content)
else:
print("Error:", response.status)
if __name__ == '__main__':
asyncio.run(main())