You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
from ispoof.spoofer.location import Location
|
|
from sqlalchemy.orm import declarative_base
|
|
from sqlalchemy import Column, DateTime, PrimaryKeyConstraint
|
|
from sqlalchemy.orm import Session
|
|
from datetime import datetime
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
class PlayerHistory(Base):
|
|
__tablename__ = "player_history"
|
|
|
|
time = Column(DateTime)
|
|
location = Column(Location)
|
|
PrimaryKeyConstraint(time, name="history_pk")
|
|
|
|
def __init__(self, engine=None):
|
|
self.engine = engine
|
|
|
|
def get_last_activity(self):
|
|
time, location = None, None
|
|
with Session(self.engine) as session:
|
|
result = session.query(PlayerHistory).order_by(PlayerHistory.time.desc()).first()
|
|
if result:
|
|
time, location = result.time, result.location
|
|
session.commit()
|
|
|
|
return time, location
|
|
|
|
def add_activity(self, location: Location):
|
|
with Session(self.engine) as session:
|
|
self.time = datetime.now()
|
|
self.location = location
|
|
session.add(self)
|
|
session.commit()
|
|
return True
|