parent
7a0ad476eb
commit
a6865f7a4a
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,13 @@
|
||||
from ispoof.objects import Pokemon, Raid
|
||||
from ispoof.lists.playerhistory import PlayerHistory
|
||||
from sqlalchemy.engine import Engine
|
||||
from sqlalchemy.exc import ArgumentError
|
||||
|
||||
|
||||
def initialize_database(engine: Engine):
|
||||
try:
|
||||
Pokemon.metadata.create_all(engine)
|
||||
Raid.metadata.create_all(engine)
|
||||
PlayerHistory.metadata.create_all(engine)
|
||||
except ArgumentError:
|
||||
print("Exception")
|
@ -0,0 +1,39 @@
|
||||
import sqlalchemy.exc
|
||||
from geopy.geocoders import Nominatim
|
||||
from ..core.location import Location
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from sqlalchemy import Column, DateTime, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime, timedelta
|
||||
from math import ceil
|
||||
|
||||
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
|
@ -1,9 +0,0 @@
|
||||
class Object():
|
||||
def __init__(self, location=None):
|
||||
self.location = location
|
||||
|
||||
def distance_to(self, other):
|
||||
return self.location.distance(other)
|
||||
|
||||
def cooldown_to(self, other):
|
||||
return self.location.get_cooldown(other) + 1
|
Loading…
Reference in new issue