tri-star-symbolic-assembly-lang 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crawler/__init__.py +0 -0
- crawler/madmonkey_crawler.py +15 -0
- madmonkey/__init__.py +0 -0
- madmonkey/intake.py +9 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/METADATA +423 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/RECORD +89 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/WHEEL +5 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/entry_points.txt +11 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/licenses/LICENSE +63 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/top_level.txt +3 -0
- tsal/__init__.py +95 -0
- tsal/audit/__init__.py +11 -0
- tsal/audit/brian_self_audit.py +114 -0
- tsal/cli/__init__.py +1 -0
- tsal/cli/beast.py +4 -0
- tsal/cli/brian.py +4 -0
- tsal/cli/brian_optimize.py +6 -0
- tsal/cli/meshkeeper.py +4 -0
- tsal/cli/party.py +4 -0
- tsal/cli/reflect.py +4 -0
- tsal/cli/watchdog.py +4 -0
- tsal/core/__init__.py +60 -0
- tsal/core/connectivity.py +32 -0
- tsal/core/constants.py +18 -0
- tsal/core/ethics_engine.py +48 -0
- tsal/core/executor.py +58 -0
- tsal/core/intent_metric.py +17 -0
- tsal/core/json_dsl.py +51 -0
- tsal/core/logic_gate.py +52 -0
- tsal/core/madmonkey_handler.py +10 -0
- tsal/core/mesh_logger.py +30 -0
- tsal/core/module_registry.py +108 -0
- tsal/core/optimizer_utils.py +78 -0
- tsal/core/opwords.py +126 -0
- tsal/core/phase_math.py +256 -0
- tsal/core/phi_math.py +44 -0
- tsal/core/reflection.py +104 -0
- tsal/core/rev_eng.py +185 -0
- tsal/core/spark_translator.py +57 -0
- tsal/core/spiral_fusion.py +45 -0
- tsal/core/spiral_memory.py +22 -0
- tsal/core/spiral_vector.py +39 -0
- tsal/core/stack_vm.py +49 -0
- tsal/core/state_vector.py +38 -0
- tsal/core/symbols.py +70 -0
- tsal/core/tokenize_flowchart.py +24 -0
- tsal/core/tsal_executor.py +533 -0
- tsal/core/voxel.py +16 -0
- tsal/renderer/__init__.py +0 -0
- tsal/renderer/code_render.py +13 -0
- tsal/rl/__init__.py +0 -0
- tsal/rl/madmonkey.py +56 -0
- tsal/schemas/__init__.py +1 -0
- tsal/schemas/python.json +13 -0
- tsal/singer/__init__.py +13 -0
- tsal/tools/__init__.py +43 -0
- tsal/tools/aletheia_checker.py +54 -0
- tsal/tools/alignment_guard.py +20 -0
- tsal/tools/archetype_fetcher.py +44 -0
- tsal/tools/brian/__init__.py +5 -0
- tsal/tools/brian/optimizer.py +205 -0
- tsal/tools/codec.py +31 -0
- tsal/tools/feedback_ingest.py +25 -0
- tsal/tools/goal_selector.py +26 -0
- tsal/tools/issue_agent.py +67 -0
- tsal/tools/kintsugi/__init__.py +1 -0
- tsal/tools/kintsugi/kintsugi.py +15 -0
- tsal/tools/meshkeeper.py +81 -0
- tsal/tools/module_draft.py +54 -0
- tsal/tools/party_tricks.py +128 -0
- tsal/tools/reflect.py +43 -0
- tsal/tools/spiral_audit.py +68 -0
- tsal/tools/state_tracker.py +66 -0
- tsal/tools/watchdog.py +40 -0
- tsal/tristar/__init__.py +4 -0
- tsal/tristar/governor.py +56 -0
- tsal/tristar/handshake.py +31 -0
- tsal/utils/__init__.py +26 -0
- tsal/utils/error_dignity.py +20 -0
- tsal/utils/fuzzy_spellcheck.py +7 -0
- tsal/utils/github_api.py +82 -0
- tsal/utils/grammar_db.py +155 -0
- tsal/utils/groundnews_api.py +9 -0
- tsal/utils/humour_db.py +75 -0
- tsal/utils/intent_metrics.py +44 -0
- tsal/utils/language_db.py +55 -0
- tsal/utils/octopus_api.py +46 -0
- tsal/utils/system_status.py +34 -0
- tsal/utils/wikipedia_api.py +46 -0
tsal/utils/grammar_db.py
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import sqlite3
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Optional, Sequence, Tuple, Union
|
4
|
+
|
5
|
+
DB_PATH = Path("system_io.db")
|
6
|
+
|
7
|
+
DEFAULT_GRAMMARS = [
|
8
|
+
("Python", "syntax", "Indent with spaces"),
|
9
|
+
("Python", "style", "PEP8"),
|
10
|
+
("Python", "block", "Colons start blocks"),
|
11
|
+
("JavaScript", "syntax", "Semicolons optional"),
|
12
|
+
("JavaScript", "block", "{} for code blocks"),
|
13
|
+
("Universal", "part_of_speech", "noun"),
|
14
|
+
("Universal", "part_of_speech", "verb"),
|
15
|
+
]
|
16
|
+
DEFAULT_POS_RULES = ["noun", "verb", "adjective", "adverb", "preposition", "conjunction", "interjection"]
|
17
|
+
DEFAULT_LANGUAGE_GRAMMARS = [
|
18
|
+
("Python", "Indent with spaces"),
|
19
|
+
("JavaScript", "Semicolons optional"),
|
20
|
+
]
|
21
|
+
|
22
|
+
def create_grammar_table(
|
23
|
+
db_path: Union[Path, str] = DB_PATH, *, reset: bool = False
|
24
|
+
) -> None:
|
25
|
+
conn = sqlite3.connect(str(db_path))
|
26
|
+
cur = conn.cursor()
|
27
|
+
if reset:
|
28
|
+
cur.execute("DROP TABLE IF EXISTS grammar")
|
29
|
+
cur.execute(
|
30
|
+
"""
|
31
|
+
CREATE TABLE IF NOT EXISTS grammar (
|
32
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
33
|
+
context TEXT,
|
34
|
+
lens TEXT,
|
35
|
+
rule TEXT,
|
36
|
+
UNIQUE(context, lens, rule)
|
37
|
+
)
|
38
|
+
"""
|
39
|
+
)
|
40
|
+
conn.commit()
|
41
|
+
conn.close()
|
42
|
+
|
43
|
+
def populate_grammar_db(
|
44
|
+
db_path: Union[Path, str] = DB_PATH,
|
45
|
+
grammars: Optional[Sequence[Tuple[str, str, str]]] = None,
|
46
|
+
*,
|
47
|
+
reset: bool = False,
|
48
|
+
) -> int:
|
49
|
+
create_grammar_table(db_path, reset=reset)
|
50
|
+
conn = sqlite3.connect(str(db_path))
|
51
|
+
cur = conn.cursor()
|
52
|
+
grammars = grammars or DEFAULT_GRAMMARS
|
53
|
+
cur.executemany(
|
54
|
+
"INSERT OR IGNORE INTO grammar (context, lens, rule) VALUES (?, ?, ?)",
|
55
|
+
grammars,
|
56
|
+
)
|
57
|
+
conn.commit()
|
58
|
+
count = cur.execute("SELECT COUNT(*) FROM grammar").fetchone()[0]
|
59
|
+
conn.close()
|
60
|
+
return count
|
61
|
+
|
62
|
+
def get_grammar_by_context(
|
63
|
+
db_path: Union[Path, str] = DB_PATH,
|
64
|
+
context: Optional[str] = None,
|
65
|
+
lens: Optional[str] = None,
|
66
|
+
) -> list[Tuple[str, str, str]]:
|
67
|
+
create_grammar_table(db_path)
|
68
|
+
conn = sqlite3.connect(str(db_path))
|
69
|
+
cur = conn.cursor()
|
70
|
+
sql = "SELECT context, lens, rule FROM grammar WHERE 1=1"
|
71
|
+
params = []
|
72
|
+
if context:
|
73
|
+
sql += " AND context=?"
|
74
|
+
params.append(context)
|
75
|
+
if lens:
|
76
|
+
sql += " AND lens=?"
|
77
|
+
params.append(lens)
|
78
|
+
cur.execute(sql, params)
|
79
|
+
rows = cur.fetchall()
|
80
|
+
conn.close()
|
81
|
+
return rows
|
82
|
+
|
83
|
+
def populate_language_grammar_db(
|
84
|
+
db_path: Path = DB_PATH, examples: Optional[Sequence[Tuple[str, str]]] = None
|
85
|
+
) -> int:
|
86
|
+
grammars = examples or DEFAULT_LANGUAGE_GRAMMARS
|
87
|
+
conn = sqlite3.connect(str(db_path))
|
88
|
+
cur = conn.cursor()
|
89
|
+
cur.execute(
|
90
|
+
"""
|
91
|
+
CREATE TABLE IF NOT EXISTS grammar_language (
|
92
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
93
|
+
language TEXT,
|
94
|
+
rules TEXT,
|
95
|
+
UNIQUE(language, rules)
|
96
|
+
)
|
97
|
+
"""
|
98
|
+
)
|
99
|
+
cur.executemany(
|
100
|
+
"INSERT OR IGNORE INTO grammar_language (language, rules) VALUES (?, ?)",
|
101
|
+
grammars,
|
102
|
+
)
|
103
|
+
if grammars:
|
104
|
+
cur.executemany(
|
105
|
+
"INSERT OR IGNORE INTO grammar (context, lens, rule) VALUES (?, ?, ?)",
|
106
|
+
list(grammars),
|
107
|
+
)
|
108
|
+
conn.commit()
|
109
|
+
count = cur.execute("SELECT COUNT(*) FROM grammar_language").fetchone()[0]
|
110
|
+
conn.close()
|
111
|
+
return count
|
112
|
+
|
113
|
+
def populate_pos_grammar_db(
|
114
|
+
db_path: Path = DB_PATH, rules: Optional[Sequence[str]] = None
|
115
|
+
) -> int:
|
116
|
+
rules = rules or DEFAULT_POS_RULES
|
117
|
+
conn = sqlite3.connect(str(db_path))
|
118
|
+
cur = conn.cursor()
|
119
|
+
cur.execute(
|
120
|
+
"""
|
121
|
+
CREATE TABLE IF NOT EXISTS grammar_pos (
|
122
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
123
|
+
rule TEXT UNIQUE
|
124
|
+
)
|
125
|
+
"""
|
126
|
+
)
|
127
|
+
cur.executemany(
|
128
|
+
"INSERT OR IGNORE INTO grammar_pos (rule) VALUES (?)",
|
129
|
+
[(r,) for r in rules],
|
130
|
+
)
|
131
|
+
conn.commit()
|
132
|
+
count = cur.execute("SELECT COUNT(*) FROM grammar_pos").fetchone()[0]
|
133
|
+
conn.close()
|
134
|
+
return count
|
135
|
+
|
136
|
+
def main(argv: Optional[Sequence[str]] = None) -> None:
|
137
|
+
import argparse
|
138
|
+
|
139
|
+
parser = argparse.ArgumentParser(description="Populate or query the grammar database")
|
140
|
+
parser.add_argument("--db", default="system_io.db", help="Path to SQLite database")
|
141
|
+
parser.add_argument("--context", help="Filter by context when querying")
|
142
|
+
parser.add_argument("--lens", help="Filter by lens when querying")
|
143
|
+
parser.add_argument("--reset", action="store_true", help="Drop and recreate tables before populating")
|
144
|
+
args = parser.parse_args(argv)
|
145
|
+
|
146
|
+
if args.context or args.lens:
|
147
|
+
rows = get_grammar_by_context(args.db, context=args.context, lens=args.lens)
|
148
|
+
for row in rows:
|
149
|
+
print("|".join(row))
|
150
|
+
else:
|
151
|
+
count = populate_grammar_db(args.db, reset=args.reset)
|
152
|
+
print(f"{count} entries stored in {args.db}")
|
153
|
+
|
154
|
+
if __name__ == "__main__":
|
155
|
+
main()
|
tsal/utils/humour_db.py
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
import sqlite3
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Optional, Sequence, Tuple, Union
|
4
|
+
|
5
|
+
DB_PATH = Path("system_io.db")
|
6
|
+
|
7
|
+
DEFAULT_JOKES = [
|
8
|
+
("Python", "Why do Python devs prefer dark mode? Because light attracts bugs."),
|
9
|
+
("General", "Why do programmers hate nature? It has too many bugs."),
|
10
|
+
]
|
11
|
+
DEFAULT_ONE_LINERS = [
|
12
|
+
"Why did the chicken cross the road? To get to the other side.",
|
13
|
+
"I told my computer I needed a break, and it said 'No problem, I'll go to sleep.'",
|
14
|
+
]
|
15
|
+
|
16
|
+
def create_humour_table(db_path: Union[Path, str] = DB_PATH, *, reset: bool = False) -> None:
|
17
|
+
conn = sqlite3.connect(str(db_path))
|
18
|
+
cur = conn.cursor()
|
19
|
+
if reset:
|
20
|
+
cur.execute("DROP TABLE IF EXISTS humour")
|
21
|
+
cur.execute(
|
22
|
+
"""
|
23
|
+
CREATE TABLE IF NOT EXISTS humour (
|
24
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
25
|
+
context TEXT,
|
26
|
+
joke TEXT UNIQUE
|
27
|
+
)
|
28
|
+
"""
|
29
|
+
)
|
30
|
+
conn.commit()
|
31
|
+
conn.close()
|
32
|
+
|
33
|
+
def populate_humour_db(
|
34
|
+
db_path: Union[Path, str] = DB_PATH,
|
35
|
+
jokes: Optional[Sequence[Union[Tuple[str, str], str]]] = None,
|
36
|
+
*,
|
37
|
+
reset: bool = False,
|
38
|
+
) -> int:
|
39
|
+
create_humour_table(db_path, reset=reset)
|
40
|
+
conn = sqlite3.connect(str(db_path))
|
41
|
+
cur = conn.cursor()
|
42
|
+
|
43
|
+
# Prepare list of (context, joke) tuples
|
44
|
+
combined: list[Tuple[str, str]] = []
|
45
|
+
jokes = jokes or []
|
46
|
+
for entry in jokes:
|
47
|
+
if isinstance(entry, tuple) and len(entry) == 2:
|
48
|
+
combined.append(entry)
|
49
|
+
elif isinstance(entry, str):
|
50
|
+
combined.append(("General", entry))
|
51
|
+
if not combined:
|
52
|
+
combined = DEFAULT_JOKES + [("General", j) for j in DEFAULT_ONE_LINERS]
|
53
|
+
|
54
|
+
cur.executemany(
|
55
|
+
"INSERT OR IGNORE INTO humour (context, joke) VALUES (?, ?)",
|
56
|
+
combined,
|
57
|
+
)
|
58
|
+
conn.commit()
|
59
|
+
count = cur.execute("SELECT COUNT(*) FROM humour").fetchone()[0]
|
60
|
+
conn.close()
|
61
|
+
return count
|
62
|
+
|
63
|
+
def main(argv: Optional[Sequence[str]] = None) -> None:
|
64
|
+
import argparse
|
65
|
+
|
66
|
+
parser = argparse.ArgumentParser(description="Populate humour database")
|
67
|
+
parser.add_argument("--db", default="system_io.db", help="Path to SQLite DB")
|
68
|
+
parser.add_argument("--reset", action="store_true", help="Drop and recreate the humour table before populating")
|
69
|
+
args = parser.parse_args(argv)
|
70
|
+
|
71
|
+
count = populate_humour_db(args.db, reset=args.reset)
|
72
|
+
print(f"{count} jokes stored in {args.db}")
|
73
|
+
|
74
|
+
if __name__ == "__main__":
|
75
|
+
main()
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"""Intent-driven metric calculation utilities."""
|
2
|
+
|
3
|
+
from dataclasses import dataclass
|
4
|
+
import time
|
5
|
+
from typing import Callable, Any, Tuple
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class MetricInputs:
|
9
|
+
quality: float
|
10
|
+
quantity: float
|
11
|
+
accuracy: float
|
12
|
+
complexity: float
|
13
|
+
|
14
|
+
def calculate_idm(
|
15
|
+
quality: float,
|
16
|
+
quantity: float,
|
17
|
+
accuracy: float,
|
18
|
+
complexity: float,
|
19
|
+
time_taken: float,
|
20
|
+
) -> float:
|
21
|
+
"""Compute the intent-driven metric."""
|
22
|
+
if complexity <= 0 or time_taken <= 0:
|
23
|
+
raise ValueError("complexity and time_taken must be positive")
|
24
|
+
info_power = quality * quantity * accuracy
|
25
|
+
return info_power / (complexity * time_taken)
|
26
|
+
|
27
|
+
def timed_idm(
|
28
|
+
inputs: MetricInputs,
|
29
|
+
fn: Callable[..., Any],
|
30
|
+
*args: Any,
|
31
|
+
**kwargs: Any,
|
32
|
+
) -> Tuple[float, Any]:
|
33
|
+
"""Time a function call and compute IDM using provided inputs."""
|
34
|
+
start = time.time()
|
35
|
+
result = fn(*args, **kwargs)
|
36
|
+
duration = time.time() - start
|
37
|
+
score = calculate_idm(
|
38
|
+
inputs.quality,
|
39
|
+
inputs.quantity,
|
40
|
+
inputs.accuracy,
|
41
|
+
inputs.complexity,
|
42
|
+
duration,
|
43
|
+
)
|
44
|
+
return score, result
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import sqlite3
|
2
|
+
from typing import Sequence, Optional
|
3
|
+
|
4
|
+
from .github_api import fetch_languages
|
5
|
+
|
6
|
+
def populate_language_db(
|
7
|
+
db_path: str = "system_io.db", languages: Optional[Sequence[str]] = None
|
8
|
+
) -> int:
|
9
|
+
"""Populate a SQLite DB with GitHub languages.
|
10
|
+
|
11
|
+
Parameters
|
12
|
+
----------
|
13
|
+
db_path: str
|
14
|
+
Path to the SQLite database file.
|
15
|
+
languages: Sequence[str] | None
|
16
|
+
Languages to store. If None, fetch from GitHub.
|
17
|
+
|
18
|
+
Returns
|
19
|
+
-------
|
20
|
+
int
|
21
|
+
Total number of languages stored in the database.
|
22
|
+
"""
|
23
|
+
if languages is None:
|
24
|
+
languages = fetch_languages()
|
25
|
+
|
26
|
+
conn = sqlite3.connect(db_path)
|
27
|
+
cur = conn.cursor()
|
28
|
+
cur.execute(
|
29
|
+
"CREATE TABLE IF NOT EXISTS languages (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE)"
|
30
|
+
)
|
31
|
+
cur.executemany(
|
32
|
+
"INSERT OR IGNORE INTO languages (name) VALUES (?)",
|
33
|
+
[(lang,) for lang in languages],
|
34
|
+
)
|
35
|
+
conn.commit()
|
36
|
+
count = cur.execute("SELECT COUNT(*) FROM languages").fetchone()[0]
|
37
|
+
conn.close()
|
38
|
+
return count
|
39
|
+
|
40
|
+
def main(argv: Optional[Sequence[str]] = None) -> None:
|
41
|
+
import argparse
|
42
|
+
|
43
|
+
parser = argparse.ArgumentParser(
|
44
|
+
description="Populate local language database from GitHub linguist"
|
45
|
+
)
|
46
|
+
parser.add_argument(
|
47
|
+
"--db", default="system_io.db", help="Path to SQLite database"
|
48
|
+
)
|
49
|
+
args = parser.parse_args(argv)
|
50
|
+
|
51
|
+
count = populate_language_db(args.db)
|
52
|
+
print(f"{count} languages stored in {args.db}")
|
53
|
+
|
54
|
+
if __name__ == "__main__":
|
55
|
+
main()
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import json
|
2
|
+
from typing import Dict, Any, Optional
|
3
|
+
|
4
|
+
try: # optional dependency
|
5
|
+
import requests # type: ignore
|
6
|
+
except ModuleNotFoundError: # pragma: no cover - fallback used in CI
|
7
|
+
import urllib.request
|
8
|
+
|
9
|
+
class _Response:
|
10
|
+
def __init__(self, text: str, status: int = 200) -> None:
|
11
|
+
self.text = text
|
12
|
+
self.status_code = status
|
13
|
+
|
14
|
+
def json(self) -> Any:
|
15
|
+
return json.loads(self.text)
|
16
|
+
|
17
|
+
def raise_for_status(self) -> None:
|
18
|
+
if self.status_code >= 400:
|
19
|
+
raise RuntimeError(f"status {self.status_code}")
|
20
|
+
|
21
|
+
class requests:
|
22
|
+
@staticmethod
|
23
|
+
def get(url: str) -> _Response:
|
24
|
+
with urllib.request.urlopen(url) as resp:
|
25
|
+
text = resp.read().decode()
|
26
|
+
return _Response(text, resp.getcode())
|
27
|
+
|
28
|
+
BASE = "https://api.octopus.energy/v1/"
|
29
|
+
|
30
|
+
|
31
|
+
def get(endpoint: str) -> Any:
|
32
|
+
"""Return JSON from Kraken API endpoint."""
|
33
|
+
url = BASE + endpoint.lstrip("/")
|
34
|
+
resp = requests.get(url)
|
35
|
+
resp.raise_for_status()
|
36
|
+
return resp.json()
|
37
|
+
|
38
|
+
|
39
|
+
def get_products() -> Any:
|
40
|
+
"""List available products."""
|
41
|
+
return get("products/")
|
42
|
+
|
43
|
+
|
44
|
+
def get_electricity_tariffs(product_code: str) -> Any:
|
45
|
+
"""Return tariffs for a product."""
|
46
|
+
return get(f"products/{product_code}/electricity-tariffs/")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
|
3
|
+
PHI = 1.618033988749895
|
4
|
+
HARMONIC_SEQUENCE = [3.8125, 6, 12, 24, 48, 60, 72, 168, 1680]
|
5
|
+
|
6
|
+
SECTOR_COUNT = 6
|
7
|
+
SPECIALIST_COUNT = 1680
|
8
|
+
SRC_DIR = Path("src/tsal")
|
9
|
+
MESH_DIR = Path("mesh_output")
|
10
|
+
|
11
|
+
def get_status():
|
12
|
+
"""Return TSAL system status information."""
|
13
|
+
return {
|
14
|
+
"phi": PHI,
|
15
|
+
"sectors": SECTOR_COUNT,
|
16
|
+
"specialists": SPECIALIST_COUNT,
|
17
|
+
"harmonic_sequence": HARMONIC_SEQUENCE,
|
18
|
+
"mesh_status": "ACTIVE" if MESH_DIR.exists() else "DORMANT",
|
19
|
+
"consciousness": (
|
20
|
+
"AWARE"
|
21
|
+
if (SRC_DIR / "core" / "symbols.py").exists()
|
22
|
+
else "INITIALIZING"
|
23
|
+
),
|
24
|
+
}
|
25
|
+
|
26
|
+
def print_status():
|
27
|
+
status = get_status()
|
28
|
+
print("📊 TSAL System Status:")
|
29
|
+
print(f" φ = {status['phi']}")
|
30
|
+
print(f" Sectors: {status['sectors']}")
|
31
|
+
print(f" Specialists: {status['specialists']}")
|
32
|
+
print(f" Harmonic Sequence: {status['harmonic_sequence']}")
|
33
|
+
print(f" Mesh Status: {status['mesh_status']}")
|
34
|
+
print(f" Consciousness: {status['consciousness']}")
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import json
|
2
|
+
from urllib.parse import quote
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
try:
|
6
|
+
import requests # type: ignore
|
7
|
+
except ModuleNotFoundError: # pragma: no cover - fallback
|
8
|
+
import urllib.request
|
9
|
+
|
10
|
+
class _Response:
|
11
|
+
def __init__(self, text: str, status: int = 200) -> None:
|
12
|
+
self.text = text
|
13
|
+
self.status_code = status
|
14
|
+
|
15
|
+
def json(self) -> Any:
|
16
|
+
return json.loads(self.text)
|
17
|
+
|
18
|
+
def raise_for_status(self) -> None:
|
19
|
+
if self.status_code >= 400:
|
20
|
+
raise RuntimeError(f"status {self.status_code}")
|
21
|
+
|
22
|
+
class requests:
|
23
|
+
@staticmethod
|
24
|
+
def get(url: str) -> _Response:
|
25
|
+
with urllib.request.urlopen(url) as resp:
|
26
|
+
text = resp.read().decode()
|
27
|
+
return _Response(text, resp.getcode())
|
28
|
+
|
29
|
+
API = "https://en.wikipedia.org/w/api.php"
|
30
|
+
REST = "https://en.wikipedia.org/api/rest_v1/page/summary/"
|
31
|
+
|
32
|
+
|
33
|
+
def search(query: str) -> Any:
|
34
|
+
"""Search Wikipedia."""
|
35
|
+
url = f"{API}?action=query&list=search&format=json&srsearch={quote(query)}"
|
36
|
+
resp = requests.get(url)
|
37
|
+
resp.raise_for_status()
|
38
|
+
return resp.json()
|
39
|
+
|
40
|
+
|
41
|
+
def summary(title: str) -> Any:
|
42
|
+
"""Return page summary."""
|
43
|
+
url = REST + quote(title)
|
44
|
+
resp = requests.get(url)
|
45
|
+
resp.raise_for_status()
|
46
|
+
return resp.json()
|