Upload files to "/"
This commit is contained in:
45
db.py
Normal file
45
db.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
DB_PATH = os.path.join(os.path.dirname(__file__), 'grepo.db')
|
||||
|
||||
|
||||
def get_db():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
|
||||
def init_db():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
|
||||
# Commands queue — sent from dashboard, consumed by Tampermonkey
|
||||
c.execute('''
|
||||
CREATE TABLE IF NOT EXISTS commands (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
town_id TEXT NOT NULL,
|
||||
town_name TEXT,
|
||||
type TEXT NOT NULL, -- 'build' | 'recruit'
|
||||
payload TEXT NOT NULL, -- JSON string
|
||||
status TEXT NOT NULL DEFAULT 'pending', -- pending | executing | done | failed
|
||||
result_msg TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
''')
|
||||
|
||||
# Town state — pushed by Tampermonkey every poll cycle
|
||||
c.execute('''
|
||||
CREATE TABLE IF NOT EXISTS town_state (
|
||||
town_id TEXT PRIMARY KEY,
|
||||
town_name TEXT,
|
||||
player TEXT,
|
||||
world_id TEXT,
|
||||
data TEXT NOT NULL, -- full JSON snapshot
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
''')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user