enchance data

This commit is contained in:
2026-04-20 12:24:51 +03:00
parent 5d564de336
commit bb7d7392a8
5 changed files with 129 additions and 30 deletions

View File

@@ -17,26 +17,40 @@ def receive_state():
return jsonify({'error': 'no data'}), 400
towns = data.get('towns', [])
player = data.get('player', '')
world_id = data.get('world_id', '')
player = data.get('player', '')
player_id = data.get('player_id', '')
alliance_id = str(data.get('alliance_id', '') or '')
world_id = data.get('world_id', '')
conn = get_db()
c = conn.cursor()
for town in towns:
x = town.get('x')
y = town.get('y')
sea = town.get('sea')
c.execute('''
INSERT INTO town_state (town_id, town_name, player, world_id, data, updated_at)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO town_state
(town_id, town_name, player, player_id, alliance_id, world_id, x, y, sea, data, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(town_id) DO UPDATE SET
town_name = excluded.town_name,
player = excluded.player,
world_id = excluded.world_id,
data = excluded.data,
updated_at = excluded.updated_at
town_name = excluded.town_name,
player = excluded.player,
player_id = excluded.player_id,
alliance_id = excluded.alliance_id,
world_id = excluded.world_id,
x = excluded.x,
y = excluded.y,
sea = excluded.sea,
data = excluded.data,
updated_at = excluded.updated_at
''', (
str(town['town_id']),
town.get('town_name', ''),
player,
player_id,
alliance_id,
world_id,
x, y, sea,
json.dumps(town),
datetime.utcnow().isoformat()
))