初始化项目

master
linchangqing 2 years ago
commit f8154b5bd2

1
.gitignore vendored

@ -0,0 +1 @@
__pycache__

@ -0,0 +1,2 @@
from . import network
from . import com

@ -0,0 +1,9 @@
from abc import ABCMeta, abstractmethod
class AbstractCommand(metaclass=ABCMeta):
def __init__(self, args = None):
self.args = args
@abstractmethod
def execute(self):
pass

@ -0,0 +1 @@
from .drawer_open_request import DrawerOpenRequest

@ -0,0 +1,5 @@
from command.abstract_command import AbstractCommand
class DrawerOpenRequest(AbstractCommand):
def execute(self):
print(self.args)

@ -0,0 +1 @@
from .drawer_open_request import DrawerOpenRequest

@ -0,0 +1,5 @@
from command.abstract_command import AbstractCommand
class DrawerOpenRequest(AbstractCommand):
def execute(self):
print(self.args)

@ -0,0 +1,18 @@
cabinets:
-
id: '100'
mode: com
addr: /dev/ttyUSB0
bps: 115200
actions:
-
addr: /dev/ttyUSB1
name: DrawerOpenRequest
desc: 串口开抽屉
-
id: '101'
addr: 100.64.1.1
actions:
-
name: DrawerOpenRequest
desc: 网络开抽屉

@ -0,0 +1,23 @@
from fastapi import FastAPI
import yaml
app = FastAPI()
data: dict = {}
@app.on_event('startup')
async def startup():
global data
yml = open('config.yaml', 'r', encoding='utf-8')
raw = yml.read()
yml.close()
data = yaml.load(raw, Loader=yaml.FullLoader)
@app.get('/{id}')
def endpoint(id: str):
cabinets = data.get('cabinets', [])
try:
cabinet = next(filter(lambda c: c['id'] == id, cabinets))
return cabinet
except StopIteration:
return '找不到柜体'

@ -0,0 +1,19 @@
annotated-types==0.5.0
anyio==3.7.1
click==8.1.6
exceptiongroup==1.1.2
fastapi==0.100.0
h11==0.14.0
httptools==0.6.0
idna==3.4
pydantic==2.1.1
pydantic_core==2.4.0
python-dotenv==1.0.0
PyYAML==6.0.1
sniffio==1.3.0
starlette==0.27.0
typing_extensions==4.7.1
uvicorn==0.23.1
uvloop==0.17.0
watchfiles==0.19.0
websockets==11.0.3
Loading…
Cancel
Save