1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00

Create old isaac runs parser

This commit is contained in:
Steffo 2019-02-06 20:11:10 +01:00
parent 51177e5cc7
commit aed099f76a
2 changed files with 84 additions and 2 deletions

31
db.py
View file

@ -1316,8 +1316,35 @@ class MatchPartecipation(Base):
return f"<MatchPartecipation {self.user.username} in {self.match.match_title}>"
class IsaacQuest(Base, Mini):
...
class BindingOfIsaac(Base, Mini):
__tablename__ = "bindingofisaac"
steam_id = Column(String, ForeignKey("steam.steam_id"), primary_key=True)
steam = relationship("Steam", backref="binding_of_isaac", lazy="joined")
daily_victories = Column(Integer, default=0)
def __repr__(self):
return f"<db.BindingOfIsaac {self.steam_id}>"
def recalc_victories(self):
raise NotImplementedError() # TODO
class BindingOfIsaacRun(Base):
__tablename__ = "bindingofisaacruns"
__table_args__ = (PrimaryKeyConstraint("date", "player_id"),)
date = Column(Date)
player_id = Column(String, ForeignKey("bindingofisaac.steam_id"))
player = relationship("BindingOfIsaac", backref="runs", lazy="joined")
score = Column(BigInteger)
# time = Column(???)
def __repr__(self):
return f"<db.BindingOfIsaacRun {self.steam_id}: {self.score}>"
# If run as script, create all the tables in the db

55
isaacfetcher.py Normal file
View file

@ -0,0 +1,55 @@
import steamleaderboards
import datetime
import db
import time
import telegram
import configparser
def dates_generator(last_date: datetime.date):
date = datetime.date.today()
while True:
if date < last_date:
return
yield date
date -= datetime.timedelta(days=1)
session = db.Session()
players = session.query(db.BindingOfIsaac).all()
config = configparser.ConfigParser()
config.read("config.ini")
print("Fetching leaderboardgroup...")
isaac = steamleaderboards.LeaderboardGroup(250900)
telegram_bot = telegram.Bot(config["Telegram"]["bot_token"])
for date in dates_generator(datetime.date(year=2017, month=1, day=3)):
lb_name = "{year:04d}{month:02d}{day:02d}_scores+".format(year=date.year, month=date.month, day=date.day)
print(f"Fetching {lb_name}...")
leaderboard = isaac.get(name=lb_name)
print(f"Finding players...")
runs = []
for player in players:
entry = leaderboard.find_entry(player.steam_id)
if entry is None:
continue
print(f"Found new entry: {entry}")
run = db.BindingOfIsaacRun(player=player, score=entry.score, date=date)
runs.append(run)
session.add(run)
if len(runs) > 1:
runs.sort(key=lambda x: x.score)
best = runs[-1]
best.player.daily_victories += 1
try:
telegram_bot.send_message(config["Telegram"]["main_group"],
f"🏆 **{best.player.steam.persona_name}** ha vinto la Daily Run di Isaac del {date.isoformat()}!",
parse_mode="HTML", disable_web_page_preview=True, disable_notification=True)
except Exception:
pass
session.commit()
print("Sleeping 5s...")
time.sleep(5)