Ready to run.
This commit is contained in:
parent
79d4e850da
commit
8b212187d1
4
Makefile
4
Makefile
@ -1,7 +1,7 @@
|
||||
BIN = ./.venv/bin/
|
||||
PYTHON = ./.venv/bin/python
|
||||
PIP = ./.venv/bin/pip
|
||||
APP_NAME=boeh
|
||||
APP_NAME=rwebgui
|
||||
|
||||
all: install build
|
||||
|
||||
@ -24,5 +24,5 @@ build:
|
||||
$(PYTHON) -m build
|
||||
|
||||
run:
|
||||
$(BIN)$(APP_NAME) --port=3028
|
||||
$(BIN)$(APP_NAME).serve --port=3080
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
from nio import AsyncClient, RoomMessageText
|
||||
import random
|
||||
|
||||
from nio import AsyncClient, RoomMessageText
|
||||
|
||||
|
||||
class BooeehBot:
|
||||
|
||||
def generate_boeh(self):
|
||||
|
@ -1,9 +1,10 @@
|
||||
from rwebgui.app import Application
|
||||
from aiohttp import web
|
||||
import asyncio
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor as Executor
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
from rwebgui.app import Application
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
|
@ -1,12 +1,14 @@
|
||||
import pathlib
|
||||
from aiohttp import web
|
||||
import uuid
|
||||
from app.app import Application as BaseApplication
|
||||
from rwebgui.component import Component
|
||||
import traceback
|
||||
import time
|
||||
import asyncio
|
||||
import json
|
||||
import pathlib
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from aiohttp import web
|
||||
from app.app import Application as BaseApplication
|
||||
|
||||
from rwebgui.component import Component
|
||||
|
||||
|
||||
class EvalBox(Component):
|
||||
|
||||
@ -21,18 +23,18 @@ class EvalBox(Component):
|
||||
await self.set_attr("value", value)
|
||||
except:
|
||||
pass
|
||||
except AttributeError as ex:
|
||||
except AttributeError:
|
||||
print(value)
|
||||
return value
|
||||
|
||||
|
||||
|
||||
class Button(Component):
|
||||
|
||||
async def on_click(self, event):
|
||||
component = self.app.search
|
||||
await component.set_attr("value", "Woeiii")
|
||||
|
||||
|
||||
class Button1(Component):
|
||||
|
||||
async def on_click(self, event):
|
||||
@ -41,11 +43,12 @@ class Button1(Component):
|
||||
value = await field.get_style("display", "block")
|
||||
await self.set_attr("innerText", value)
|
||||
|
||||
class RandomString(Component):
|
||||
|
||||
class RandomString(Component):
|
||||
|
||||
async def task_random(self):
|
||||
import random
|
||||
|
||||
rand_bytes = [random.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(15)]
|
||||
random_data = "".join(rand_bytes)
|
||||
while True:
|
||||
@ -54,6 +57,7 @@ class RandomString(Component):
|
||||
await self.set_attr("innerHTML", random_data)
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
|
||||
class Counter(Component):
|
||||
|
||||
async def task_test(self):
|
||||
@ -61,8 +65,6 @@ class Counter(Component):
|
||||
await asyncio.sleep(10)
|
||||
print("Slow task")
|
||||
|
||||
|
||||
|
||||
async def task_increment(self):
|
||||
if not self.value:
|
||||
self.value = 0
|
||||
@ -75,24 +77,29 @@ class Counter(Component):
|
||||
await self.set_attr("value", self.value)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
class GPT(Component):
|
||||
|
||||
class Children:
|
||||
prompt = Component
|
||||
answer = Component
|
||||
|
||||
class submit(Component):
|
||||
async def trigger(self, id_, event, data):
|
||||
print("GOGOG", event, data)
|
||||
return await super().trigger(id_, event, data)
|
||||
|
||||
async def on_click(self, data):
|
||||
from xmlrpc.client import ServerProxy
|
||||
|
||||
client = ServerProxy("https://api.molodetz.nl/rpc")
|
||||
prompt = await self.app.prompt.get_attr("value")
|
||||
print(prompt)
|
||||
exit(0)
|
||||
|
||||
await self.answer.set_attr("value", client.gpt4o(prompt))
|
||||
return {"event_id":data['event_id'],"success":True}
|
||||
return {"event_id": data["event_id"], "success": True}
|
||||
|
||||
|
||||
class SpeedMeter(Component):
|
||||
|
||||
@ -106,7 +113,7 @@ class SpeedMeter(Component):
|
||||
bytes_received = self.bytes_received
|
||||
self.bytes_received = 0
|
||||
|
||||
await self.set_attr("value","{} kb/s".format(bytes_received / 1000))
|
||||
await self.set_attr("value", f"{bytes_received / 1000} kb/s")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def trigger(self, id_, event, data):
|
||||
@ -142,13 +149,13 @@ class Application(BaseApplication):
|
||||
self.location_static = self.location.joinpath("static")
|
||||
self.template_path = self.location.joinpath("templates")
|
||||
super().__init__(template_path=self.template_path)
|
||||
self.router.add_static('/static', self.location_static)
|
||||
self.router.add_static("/static", self.location_static)
|
||||
self.router.add_get("/", self.index_handler)
|
||||
self.router.add_get("/ws/{uuid}", self.websocket_handler)
|
||||
|
||||
async def websocket_handler(self, request):
|
||||
# Extract the UUID from the route
|
||||
uuid_value = request.match_info['uuid']
|
||||
uuid_value = request.match_info["uuid"]
|
||||
|
||||
# Validate if it's a valid UUID
|
||||
try:
|
||||
@ -166,7 +173,5 @@ class Application(BaseApplication):
|
||||
|
||||
return ws
|
||||
|
||||
|
||||
|
||||
async def index_handler(self, request):
|
||||
return await self.render_template("index.html", request, {})
|
||||
|
@ -1,10 +1,10 @@
|
||||
import uuid
|
||||
import json
|
||||
import time
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
|
||||
class Component:
|
||||
|
||||
@classmethod
|
||||
@ -34,6 +34,7 @@ class Component:
|
||||
instance.app = self
|
||||
instance.ws = self.ws
|
||||
setattr(self, name, instance)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
obj = cls(None, None)
|
||||
@ -57,7 +58,11 @@ class Component:
|
||||
|
||||
@property
|
||||
def tasks(self):
|
||||
tasks_ = [getattr(self, name) for name in dir(self) if name.startswith("task_") and hasattr(self, name)]
|
||||
tasks_ = [
|
||||
getattr(self, name)
|
||||
for name in dir(self)
|
||||
if name.startswith("task_") and hasattr(self, name)
|
||||
]
|
||||
for child in self.children:
|
||||
tasks_ += child.tasks # .extend(await child.get_tasks())
|
||||
return tasks_
|
||||
@ -80,7 +85,6 @@ class Component:
|
||||
def callbacks(self):
|
||||
return hasattr(self.app, "callbacks") and self.app.callbacks or self._callbacks
|
||||
|
||||
|
||||
async def trigger(self, id_, event, data):
|
||||
if self.id == id_:
|
||||
method_name = "on_" + event
|
||||
@ -104,24 +108,25 @@ class Component:
|
||||
future = loop.create_future()
|
||||
|
||||
self.callbacks[event_id] = lambda data: future.set_result(data)
|
||||
await self.ws.send_json({
|
||||
await self.ws.send_json(
|
||||
{
|
||||
"event_id": event_id,
|
||||
"event": "call",
|
||||
"id": id_ and id_ or self.id,
|
||||
"method": method,
|
||||
"args": args,
|
||||
"callback": callback
|
||||
})
|
||||
"callback": callback,
|
||||
}
|
||||
)
|
||||
if callback:
|
||||
response = await self.communicate(event_id=event_id)
|
||||
return response['result']
|
||||
return response["result"]
|
||||
# print("GLUKT")
|
||||
# return response['result']
|
||||
|
||||
return True
|
||||
# return await future
|
||||
|
||||
|
||||
async def get_attr(self, key, default=None):
|
||||
result = await self.call("getAttr", [self.id, key], True)
|
||||
return result or default
|
||||
@ -163,9 +168,6 @@ class Component:
|
||||
result = await self.call("getStyle", [self.id, key], default)
|
||||
return result or default
|
||||
|
||||
|
||||
|
||||
|
||||
async def on_keyup(self, event):
|
||||
value = await self.get_attr("value")
|
||||
if self.value != value:
|
||||
@ -174,7 +176,6 @@ class Component:
|
||||
self.value = value
|
||||
return self.value
|
||||
|
||||
|
||||
async def get_tasks(self):
|
||||
tasks = self.tasks
|
||||
for child in self.children:
|
||||
@ -199,19 +200,23 @@ class Component:
|
||||
# Echo the message back to the client
|
||||
# print(f"Received message: {msg.data}")
|
||||
data = msg.json()
|
||||
response = {"event_id":data['event_id'],"success":True}
|
||||
response['time_start'] = time.time()
|
||||
if self.callbacks.get(data['event_id']):
|
||||
self.callbacks[data['event_id']](data['result'])
|
||||
elif data.get('data') and not data['data'].get('id'):
|
||||
response['handled'] = False
|
||||
elif data.get('data'):
|
||||
response['handled'] = True
|
||||
response['data'] = await self.trigger(data['data']['id'], data['event'],data['data'])
|
||||
response['cancel'] = True
|
||||
response = {"event_id": data["event_id"], "success": True}
|
||||
response["time_start"] = time.time()
|
||||
if self.callbacks.get(data["event_id"]):
|
||||
self.callbacks[data["event_id"]](data["result"])
|
||||
elif data.get("data") and not data["data"].get("id"):
|
||||
response["handled"] = False
|
||||
elif data.get("data"):
|
||||
response["handled"] = True
|
||||
response["data"] = await self.trigger(
|
||||
data["data"]["id"], data["event"], data["data"]
|
||||
)
|
||||
response["cancel"] = True
|
||||
|
||||
response['time_end'] = time.time()
|
||||
response['time_duration'] = response['time_end'] - response['time_start']
|
||||
response["time_end"] = time.time()
|
||||
response["time_duration"] = (
|
||||
response["time_end"] - response["time_start"]
|
||||
)
|
||||
await self.ws.send_json(response)
|
||||
|
||||
# await ws.send_str(f"Echo: {msg.data}")
|
||||
@ -221,7 +226,6 @@ class Component:
|
||||
print(ex)
|
||||
pass
|
||||
|
||||
|
||||
# async def the_task():
|
||||
# while True:
|
||||
# time.sleep(1)
|
||||
@ -232,7 +236,6 @@ class Component:
|
||||
# await tasks()
|
||||
print("AFTERR")
|
||||
|
||||
|
||||
def add_child(self, child):
|
||||
child.app = self.app
|
||||
child.ws = self.ws
|
||||
|
Loading…
Reference in New Issue
Block a user