From 8fe2eebe031c65c82ae9f0ee4f239f4cfaf1f500 Mon Sep 17 00:00:00 2001 From: wqy Date: Sat, 3 Sep 2022 11:08:05 +0800 Subject: [PATCH] Get api --- api/__init__.py | 1 + api/s0_base.py | 20 ++++++++++++++++++++ tjnetwork_new.py | 12 ++++++++++++ 3 files changed, 33 insertions(+) diff --git a/api/__init__.py b/api/__init__.py index 499884c..4ea2a94 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -12,6 +12,7 @@ from .s0_base import is_node, is_junction, is_reservoir, is_tank from .s0_base import is_link, is_pipe, is_pump, is_valve from .s0_base import is_curve from .s0_base import is_pattern +from .s0_base import get_nodes, get_links, get_curves, get_patterns from .s1_title import set_title, get_title diff --git a/api/s0_base.py b/api/s0_base.py index 91e999d..87350a7 100644 --- a/api/s0_base.py +++ b/api/s0_base.py @@ -53,3 +53,23 @@ def is_curve(name: str, id: str) -> bool: def is_pattern(name: str, id: str) -> bool: return _get_from(name, id, _PATTERN) != None + +def _get_all(name: str, base_type: str) -> list[str]: + ids : list[str] = [] + with conn[name].cursor(row_factory=dict_row) as cur: + cur.execute(f"select id from {base_type} order by id") + for record in cur: + ids.append(record['id']) + return ids + +def get_nodes(name: str) -> list[str]: + return _get_all(name, _NODE) + +def get_links(name: str) -> list[str]: + return _get_all(name, _LINK) + +def get_curves(name: str) -> list[str]: + return _get_all(name, _CURVE) + +def get_patterns(name: str) -> list[str]: + return _get_all(name, _PATTERN) diff --git a/tjnetwork_new.py b/tjnetwork_new.py index d23f032..f7a3845 100644 --- a/tjnetwork_new.py +++ b/tjnetwork_new.py @@ -104,6 +104,18 @@ def is_curve(name: str, curve_id: str) -> bool: def is_pattern(name: str, pattern_id: str) -> bool: return api.is_pattern(name, pattern_id) +def get_nodes(name: str) -> list[str]: + return api.get_nodes(name) + +def get_links(name: str) -> list[str]: + return api.get_links(name) + +def get_curves(name: str) -> list[str]: + return api.get_curves(name) + +def get_patterns(name: str) -> list[str]: + return api.get_patterns(name) + ############################################################ # title 1.[TITLE]