enchance data
This commit is contained in:
@@ -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()
|
||||
))
|
||||
|
||||
@@ -23,7 +23,8 @@ def index():
|
||||
def get_towns():
|
||||
conn = get_db()
|
||||
rows = conn.execute('''
|
||||
SELECT town_id, town_name, player, world_id, data, updated_at
|
||||
SELECT town_id, town_name, player, player_id, alliance_id,
|
||||
world_id, x, y, sea, data, updated_at
|
||||
FROM town_state
|
||||
ORDER BY town_name ASC
|
||||
''').fetchall()
|
||||
@@ -33,11 +34,16 @@ def get_towns():
|
||||
for row in rows:
|
||||
d = json.loads(row['data'])
|
||||
towns.append({
|
||||
'town_id': row['town_id'],
|
||||
'town_name': row['town_name'],
|
||||
'player': row['player'],
|
||||
'world_id': row['world_id'],
|
||||
'updated_at': row['updated_at'],
|
||||
'town_id': row['town_id'],
|
||||
'town_name': row['town_name'],
|
||||
'player': row['player'],
|
||||
'player_id': row['player_id'],
|
||||
'alliance_id': row['alliance_id'],
|
||||
'world_id': row['world_id'],
|
||||
'x': row['x'],
|
||||
'y': row['y'],
|
||||
'sea': row['sea'],
|
||||
'updated_at': row['updated_at'],
|
||||
'resources': {
|
||||
'wood': d.get('wood', 0),
|
||||
'stone': d.get('stone', 0),
|
||||
@@ -45,12 +51,17 @@ def get_towns():
|
||||
'storage': d.get('storage', 0),
|
||||
'population': d.get('population', 0),
|
||||
},
|
||||
'buildings': d.get('buildings', {}),
|
||||
'units': d.get('units', {}),
|
||||
'points': d.get('points', 0),
|
||||
'god': d.get('god', None),
|
||||
'build_queue': d.get('buildingOrder', []),
|
||||
'build_data': d.get('buildData', {}),
|
||||
'buildings': d.get('buildings', {}),
|
||||
'units': d.get('units', {}),
|
||||
'points': d.get('points', 0),
|
||||
'god': d.get('god', None),
|
||||
'build_queue': d.get('buildingOrder', []),
|
||||
'build_data': d.get('buildData', {}),
|
||||
'researches': d.get('researches', {}),
|
||||
'has_premium': d.get('has_premium', False),
|
||||
'bonuses': d.get('bonuses', {}),
|
||||
'wonder_points': d.get('wonder_points', 0),
|
||||
'total_points': d.get('total_points', 0),
|
||||
})
|
||||
return jsonify(towns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user