55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script to give test users some items to drop
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
import random
|
|
|
|
sys.path.insert(0, '/app')
|
|
|
|
from api import database as db
|
|
|
|
async def give_test_users_items():
|
|
"""Give all loadtest users some random items"""
|
|
# Common items to give
|
|
items_to_give = [
|
|
'scrap_metal', 'wood', 'cloth', 'water_bottle', 'canned_food',
|
|
'medkit', 'bandage', 'rusty_pipe', 'battery', 'rope'
|
|
]
|
|
|
|
async with db.DatabaseSession() as session:
|
|
from sqlalchemy import select, insert
|
|
|
|
# Get all loadtest users
|
|
stmt = select(db.players).where(db.players.c.username.like('loadtest_user_%'))
|
|
result = await session.execute(stmt)
|
|
users = result.all()
|
|
|
|
print(f"Found {len(users)} loadtest users")
|
|
|
|
if not users:
|
|
print("No loadtest users found!")
|
|
return
|
|
|
|
# Give each user 5-10 random items
|
|
for user in users:
|
|
num_items = random.randint(5, 10)
|
|
for _ in range(num_items):
|
|
item_id = random.choice(items_to_give)
|
|
quantity = random.randint(1, 20)
|
|
|
|
stmt = insert(db.inventory).values(
|
|
player_id=user.id,
|
|
item_id=item_id,
|
|
quantity=quantity,
|
|
is_equipped=False
|
|
)
|
|
await session.execute(stmt)
|
|
|
|
await session.commit()
|
|
print(f"Gave items to {len(users)} loadtest users")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(give_test_users_items())
|