import re from sqlalchemy import ( create_engine, Column, Integer, String, Sequence, BLOB, create_engine, text, func, desc, asc, ) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from kbinxml import KBinXML import xmltodict import json import random # Define the base class for our models Base = declarative_base() db_type = "sqlite" # Change to 'mysql' to use MySQL # Declare Databases class eacNetProfile(Base): __tablename__ = "eacNetProfile" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(16), unique=True) refid = Column(String(16), unique=True) snsid = Column(String(8), unique=True) ddrTicket = Column(Integer, default=0) livelyTicket = Column(Integer, default=0) def __repr__(self): return ( f"eacNetProfile(id={self.id}, token='{self.token}',", f"refid='{self.refid}'," f"snsid='{self.snsid}'," f"ddrTicket='{self.ddrTicket}'," f"livelyTicket='{self.livelyTicket}')", ) class infProfile(Base): __tablename__ = "infinitasProfile" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13), unique=True) name = Column(String(6)) version = Column(String(20)) prefID = Column(Integer) playSP = Column(Integer, default=0) playDP = Column(Integer, default=0) achieveSP = Column(Integer, default=0) achieveDP = Column(Integer, default=0) danSP = Column(Integer, default=-1) danDP = Column(Integer, default=-1) totalPlays = Column(Integer, default=0) totalClears = Column(Integer, default=0) saveLength = Column(Integer) saveData = Column(BLOB) saveCheck = Column(String) saveDataBackup = Column(BLOB) saveLengthBackup = Column(Integer) saveCheckBackup = Column(String) bits = Column(Integer, default=0) def __repr__(self): return ( f"infProfile(id={self.id}, infinitasID='{self.infinitasID}', name='{self.name}', " f"version='{self.version}', prefID={self.prefID}, bits={self.bits}, playSP={self.playSP}, " f"playDP={self.playDP}, achieveSP={self.achieveSP}, achieveDP={self.achieveDP}, " f"danSP={self.danSP}, danDP={self.danDP}, totalPlays={self.totalPlays}, totalClears={self.totalClears}, saveLength={self.saveLength}, saveData={self.saveData}, saveCheck={self.saveCheck}, saveLengthBackup={self.saveLength}, saveDataBackup={self.saveData}, saveCheckBackup={self.saveCheck})" ) class infToken(Base): __tablename__ = "infinitasToken" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13), unique=True) token = Column(String(20), unique=True) def __repr__(self): return f"infToken(infinitasID='{self.infinitasID}', token='{self.token}')" class InfinitasPlayData(Base): __tablename__ = "infinitasPlayData" id = Column(Integer, primary_key=True) infinitasID = Column(String(13), nullable=False) musicID = Column(Integer, nullable=False) missCount = Column(String, nullable=True) # Store as JSON string playCount = Column(String, nullable=True) # Store as JSON string clearAmount = Column(String, nullable=True) # Store as JSON string clearFlag = Column(String, nullable=True) # Store as JSON string score = Column(String, nullable=True) # Store as JSON string def __repr__(self): return ( f"InfinitasPlayData(id={self.id}, " f"infinitasID='{self.infinitasID}', " f"musicID={self.musicID}, " f"missCount={self.missCount}, " f"playCount={self.playCount}, " f"clearAmount={self.clearAmount}, " f"clearFlag={self.clearFlag}, " f"score={self.score})" ) class infPlayDataExt(Base): __tablename__ = "infinitasPlayDataExt" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13)) clock = Column(Integer) musicID = Column(Integer) noteID = Column(Integer) score = Column(Integer) pgreat = Column(Integer) great = Column(Integer) miss = Column(Integer) clearType = Column(Integer) def __repr__(self): return f"infinitasPlayDataExt(infinitasID='{self.infinitasID}', token='{self.token}')" class infRivalData(Base): __tablename__ = "infinitasRivalData" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13), unique=True) spRivals = Column(String(), default="[]") dpRivals = Column(String(), default="[]") def __repr__(self): return f"infinitasRivalData(infinitasID='{self.infinitasID}', spRivals='{self.spRivals}, dpRivals='{self.dpRivals}')" class infGhostData(Base): __tablename__ = "infinitasGhostData" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13)) name = Column(String) score = Column(Integer) danRank = Column(Integer) prefecture = Column(Integer) musicID = Column(Integer) noteID = Column(Integer) ghost = Column(BLOB) ghostCheck = Column(String) ghostSize = Column(Integer) flip = Column(Integer) assist = Column(Integer) arrange1 = Column(Integer) arrange0 = Column(Integer) def __repr__(self): return ( f"infGhostData(id={self.id}, " f"infinitasID='{self.infinitasID}', " f"name='{self.name}', " f"score={self.score}, " f"danRank={self.danRank}, " f"prefecture={self.prefecture}, " f"musicID={self.musicID}, " f"noteID={self.noteID}, " f"ghost={self.ghost}, " f"ghostCheck='{self.ghostCheck}', " f"ghostSize={self.ghostSize}, " f"flip={self.flip}, " f"assist={self.assist}, " f"arrange1={self.arrange1}, " f"arrange0={self.arrange0})" ) class infItems(Base): __tablename__ = "infinitasItems" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13), unique=True) TicketsPaid = Column(Integer, default=0) TicketsFree = Column(Integer, default=0) lDiscs = Column(Integer, default=0) musicPacks = Column(String, default="[]") customizations = Column( String, default='["","I1100000","I1200000","I1300000","I1400000","I1500000","I1600000","I1700000","","I1900000","I1300000","I2100000"]', ) otherCustomizations = Column( String, default='["C1000000","C1100000","C1200000","C1300000","C1400000"]' ) def __repr__(self): return f"infinitasItems(infinitasID='{self.infinitasID}', TicketsPaid='{self.TicketsPaid}', TicketsFree='{self.TicketsFree}', lDiscs='{self.lDiscs}', musicPacks='{self.musicPacks}', customizations='{self.customizations}', otherCustomizations='{self.otherCustomizations}'" class infUnlocks(Base): __tablename__ = "infinitasUnlocks" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) infinitasID = Column(String(13)) musicID = Column(Integer, default=0) type = Column(Integer, default=0) note_bit = Column(Integer, default=0) def __repr__(self): return f"infinitasItems(infinitasID='{self.infinitasID}', musicID='{self.musicID}', type='{self.type}', note_bit='{self.note_bit}', " class DMGFProfile(Base): __tablename__ = "gitadoraProfile" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(16), unique=True) refid = Column(String(16), unique=True) did = Column(String(8), unique=True) usercode = Column(String(10), unique=True) DMskill = Column(Integer(), default=0) DMallSkill = Column(Integer(), default=0) DMoldSkill = Column(Integer(), default=-1) DMoldAllSkill = Column(Integer(), default=-1) GFskill = Column(Integer(), default=0) GFallSkill = Column(Integer(), default=0) GFoldSkill = Column(Integer(), default=-1) GFoldAllSkill = Column(Integer(), default=-1) def __repr__(self): return ( f"DMGFProfile(id={self.id}, token='{self.token}',", f"refid='{self.refid}',", f"did='{self.did}',", f"usercode='{self.usercode}',", f"DMskill='{self.DMskill}',", f"DMallSkill='{self.DMallSkill}'," f"DMoldSkill='{self.DMoldSkill}',", f"DMoldAllSkill='{self.DMoldAllSkill}',", f"GFoldAllSkill='{self.GFoldAllSkill}',", f"GFskill='{self.GFskill}',", f"GFlastMusic='{self.GFoldSkill}')", ) class DMGFProfileExt(Base): __tablename__ = "gitadoraProfileExt" musicFavorites = '"-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"' playStyleCustom = "0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 20 0" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(16), unique=True) refid = Column(String(16), unique=True) did = Column(String(8), unique=True) DMplaystyle = Column(String(), default=playStyleCustom) DMcustom = Column(String(), default=playStyleCustom) DMmusicFavorites1 = Column(String(), default=musicFavorites) DMmusicFavorites2 = Column(String(), default=musicFavorites) DMmusicFavorites3 = Column(String(), default=musicFavorites) DMlastCategory = Column(Integer(), default=0) DMlastMusic = Column(Integer(), default=-1) DMlastSeq = Column(Integer(), default=0) DMdisplayLevel = Column(Integer(), default=0) GFplaystyle = Column(String(), default=playStyleCustom) GFcustom = Column(String(), default=playStyleCustom) GFmusicFavorites1 = Column(String(), default=musicFavorites) GFmusicFavorites2 = Column(String(), default=musicFavorites) GFmusicFavorites3 = Column(String(), default=musicFavorites) GFlastCategory = Column(Integer(), default=0) GFlastMusic = Column(Integer(), default=-1) GFlastSeq = Column(Integer(), default=0) GFdisplayLevel = Column(Integer(), default=0) def __repr__(self): return ( f"DMGFProfileExt(id={self.id}, token='{self.token}', " f"refid='{self.refid}', did='{self.did}', " f"DMplaystyle='{self.DMplaystyle}', DMcustom='{self.DMcustom}', " f"DMmusicFavorites1='{self.DMmusicFavorites1}', DMmusicFavorites2='{self.DMmusicFavorites2}', " f"DMmusicFavorites3='{self.DMmusicFavorites3}', " f"DMlastCategory='{self.DMlastCategory}'," f"DMlastMusic='{self.DMlastMusic}'," f"DMlastSeq='{self.DMlastSeq}'," f"DMdisplayLevel='{self.DMdisplayLevel}'," f"GFplaystyle='{self.GFplaystyle}', GFcustom='{self.GFcustom}', " f"GFmusicFavorites1='{self.GFmusicFavorites1}', GFmusicFavorites2='{self.GFmusicFavorites2}', " f"GFmusicFavorites3='{self.GFmusicFavorites3}'," f"GFlastCategory='{self.GFlastCategory}'," f"GFlastMusic='{self.GFlastMusic}'," f"GFlastSeq='{self.GFlastSeq}" f"GFdisplayLevel='{self.GFdisplayLevel}')" ) class DMGFProfileDetails(Base): __tablename__ = "gitadoraProfileDetails" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(16), unique=True) refid = Column(String(16), unique=True) did = Column(String(8), unique=True) # Drum Mania fields DMcabid = Column(Integer, default=0) DMplay = Column(Integer, default=0) DMplaytime = Column(Integer, default=0) DMplayterm = Column(Integer, default=0) DMsession_cnt = Column(Integer, default=0) DMmatching_num = Column(Integer, default=0) DMextra_stage = Column(Integer, default=0) DMextra_play = Column(Integer, default=0) DMextra_clear = Column(Integer, default=0) DMencore_play = Column(Integer, default=0) DMencore_clear = Column(Integer, default=0) DMpencore_play = Column(Integer, default=0) DMpencore_clear = Column(Integer, default=0) DMmax_clear_diff = Column(Integer, default=0) DMmax_full_diff = Column(Integer, default=0) DMmax_exce_diff = Column(Integer, default=0) DMclear_num = Column(Integer, default=0) DMfull_num = Column(Integer, default=0) DMexce_num = Column(Integer, default=0) DMno_num = Column(Integer, default=0) DMe_num = Column(Integer, default=0) DMd_num = Column(Integer, default=0) DMc_num = Column(Integer, default=0) DMb_num = Column(Integer, default=0) DMa_num = Column(Integer, default=0) DMs_num = Column(Integer, default=0) DMss_num = Column(Integer, default=0) # Guitar Freaks fields GFcabid = Column(Integer, default=0) GFplay = Column(Integer, default=0) GFplaytime = Column(Integer, default=0) GFplayterm = Column(Integer, default=0) GFsession_cnt = Column(Integer, default=0) GFmatching_num = Column(Integer, default=0) GFextra_stage = Column(Integer, default=0) GFextra_play = Column(Integer, default=0) GFextra_clear = Column(Integer, default=0) GFencore_play = Column(Integer, default=0) GFencore_clear = Column(Integer, default=0) GFpencore_play = Column(Integer, default=0) GFpencore_clear = Column(Integer, default=0) GFmax_clear_diff = Column(Integer, default=0) GFmax_full_diff = Column(Integer, default=0) GFmax_exce_diff = Column(Integer, default=0) GFclear_num = Column(Integer, default=0) GFfull_num = Column(Integer, default=0) GFexce_num = Column(Integer, default=0) GFno_num = Column(Integer, default=0) GFe_num = Column(Integer, default=0) GFd_num = Column(Integer, default=0) GFc_num = Column(Integer, default=0) GFb_num = Column(Integer, default=0) GFa_num = Column(Integer, default=0) GFs_num = Column(Integer, default=0) GFss_num = Column(Integer, default=0) def __repr__(self): return ( f"DMGFProfileDetails(id={self.id}, token='{self.token}', " f"refid='{self.refid}', did='{self.did}', " # Drum Mania fields f"DMcabid={self.DMcabid}, " f"DMplay={self.DMplay}, " f"DMplaytime={self.DMplaytime}, " f"DMplayterm={self.DMplayterm}, " f"DMsession_cnt={self.DMsession_cnt}, " f"DMmatching_num={self.DMmatching_num}, " f"DMextra_stage={self.DMextra_stage}, " f"DMextra_play={self.DMextra_play}, " f"DMextra_clear={self.DMextra_clear}, " f"DMencore_play={self.DMencore_play}, " f"DMencore_clear={self.DMencore_clear}, " f"DMpencore_play={self.DMpencore_play}, " f"DMpencore_clear={self.DMpencore_clear}, " f"DMmax_clear_diff={self.DMmax_clear_diff}, " f"DMmax_full_diff={self.DMmax_full_diff}, " f"DMmax_exce_diff={self.DMmax_exce_diff}, " f"DMclear_num={self.DMclear_num}, " f"DMfull_num={self.DMfull_num}, " f"DMexce_num={self.DMexce_num}, " f"DMno_num={self.DMno_num}, " f"DMe_num={self.DMe_num}, " f"DMd_num={self.DMd_num}, " f"DMc_num={self.DMc_num}, " f"DMb_num={self.DMb_num}, " f"DMa_num={self.DMa_num}, " f"DMs_num={self.DMs_num}, " f"DMss_num={self.DMss_num}, " # Guitar Freaks fields f"GFcabid={self.GFcabid}, " f"GFplay={self.GFplay}, " f"GFplaytime={self.GFplaytime}, " f"GFplayterm={self.GFplayterm}, " f"GFsession_cnt={self.GFsession_cnt}, " f"GFmatching_num={self.GFmatching_num}, " f"GFextra_stage={self.GFextra_stage}, " f"GFextra_play={self.GFextra_play}, " f"GFextra_clear={self.GFextra_clear}, " f"GFencore_play={self.GFencore_play}, " f"GFencore_clear={self.GFencore_clear}, " f"GFpencore_play={self.GFpencore_play}, " f"GFpencore_clear={self.GFpencore_clear}, " f"GFmax_clear_diff={self.GFmax_clear_diff}, " f"GFmax_full_diff={self.GFmax_full_diff}, " f"GFmax_exce_diff={self.GFmax_exce_diff}, " f"GFclear_num={self.GFclear_num}, " f"GFfull_num={self.GFfull_num}, " f"GFexce_num={self.GFexce_num}, " f"GFno_num={self.GFno_num}, " f"GFe_num={self.GFe_num}, " f"GFd_num={self.GFd_num}, " f"GFc_num={self.GFc_num}, " f"GFb_num={self.GFb_num}, " f"GFa_num={self.GFa_num}, " f"GFs_num={self.GFs_num}, " f"GFss_num={self.GFss_num})" ) # Define DMGF Playlog here please class DMGFPlaylog(Base): __tablename__ = "gitadoraPlaylog" id = Column(Integer, primary_key=True) refid = Column(String(16)) token = Column(String()) game = Column(String(2)) # "DM" or "GF" # Stage data date_ms = Column(String()) stage_no = Column(Integer) musicid = Column(Integer) seq = Column(Integer) skill = Column(Integer) new_skill = Column(Integer) clear = Column(Integer) auto_clear = Column(Integer) fullcombo = Column(Integer) excellent = Column(Integer) medal = Column(Integer) perc = Column(Integer) new_perc = Column(Integer) rank = Column(Integer) score = Column(Integer) combo = Column(Integer) max_combo_perc = Column(Integer) flags = Column(Integer) phrase_combo_perc = Column(Integer) # Note counts perfect = Column(Integer) great = Column(Integer) good = Column(Integer) ok = Column(Integer) miss = Column(Integer) # Note percentages perfect_perc = Column(Integer) great_perc = Column(Integer) good_perc = Column(Integer) ok_perc = Column(Integer) miss_perc = Column(Integer) # Meter data meter = Column(String()) meter_prog = Column(Integer) before_meter = Column(String()) before_meter_prog = Column(Integer) is_new_meter = Column(Integer) # Phrase data phrase_data_num = Column(Integer) phrase_addr = Column(String()) # Store as JSON string phrase_type = Column(String()) # Store as JSON string phrase_status = Column(String()) # Store as JSON string phrase_end_addr = Column(Integer) def __repr__(self): return ( f"DMGFPlaylog(" f"id={self.id}, " f"refid='{self.refid}', " f"token='{self.token}', " f"game='{self.game}', " f"date_ms={self.date_ms}, " f"stage_no={self.stage_no}, " f"musicid={self.musicid}, " f"seq={self.seq}, " f"skill={self.skill}, " f"new_skill={self.new_skill}, " f"clear={self.clear}, " f"auto_clear={self.auto_clear}, " f"fullcombo={self.fullcombo}, " f"excellent={self.excellent}, " f"medal={self.medal}, " f"perc={self.perc}, " f"new_perc={self.new_perc}, " f"rank={self.rank}, " f"score={self.score}, " f"combo={self.combo}, " f"max_combo_perc={self.max_combo_perc}, " f"flags={self.flags}, " f"phrase_combo_perc={self.phrase_combo_perc}, " f"perfect={self.perfect}, " f"great={self.great}, " f"good={self.good}, " f"ok={self.ok}, " f"miss={self.miss}, " f"perfect_perc={self.perfect_perc}, " f"great_perc={self.great_perc}, " f"good_perc={self.good_perc}, " f"ok_perc={self.ok_perc}, " f"miss_perc={self.miss_perc}, " f"meter={self.meter}, " f"meter_prog={self.meter_prog}, " f"before_meter={self.before_meter}, " f"before_meter_prog={self.before_meter_prog}, " f"is_new_meter={self.is_new_meter}, " f"phrase_data_num={self.phrase_data_num}, " f"phrase_addr='{self.phrase_addr}', " f"phrase_type='{self.phrase_type}', " f"phrase_status='{self.phrase_status}', " f"phrase_end_addr={self.phrase_end_addr})" ) class nosProfile(Base): __tablename__ = "nostalgiaProfile" musicListFlgDefault = ( "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" ) id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(), unique=True) refid = Column(String(16), unique=True) name = Column(String(8), default="") playCount = Column(Integer, default=0) todayPlayCount = Column(Integer, default=0) oldPlayCount = Column(Integer, default=0) oldTodayPlayCount = Column(Integer, default=0) oldRecitalCount = Column(Integer, default=0) musicListFlg0 = Column(String(), default=musicListFlgDefault) musicListFlg1 = Column(String(), default=musicListFlgDefault) musicListFlg2 = Column(String(), default=musicListFlgDefault) musicListFlg3 = Column(String(), default=musicListFlgDefault) permittedlist0 = Column(String(), default=musicListFlgDefault) permittedlist1 = Column(String(), default=musicListFlgDefault) permittedlist2 = Column(String(), default=musicListFlgDefault) permittedlist3 = Column(String(), default=musicListFlgDefault) musicIndex = Column(Integer, default=0) sheetType = Column(Integer, default=0) playTime = Column(Integer, default=0) musicGroup = Column(Integer, default=0) bingoIndex = Column(Integer, default=0) performType = Column(Integer, default=0) filterFlag = Column(Integer, default=0) def __repr__(self): return ( f"nosProfile(id={self.id}, token='{self.token}', " f"refid='{self.refid}', name='{self.name}', " f"playCount={self.playCount}, todayPlayCount={self.todayPlayCount}, " f"oldPlayCount={self.oldPlayCount}, oldTodayPlayCount={self.oldTodayPlayCount}, oldRecitalCount={self.oldRecitalCount}, " f"musicListFlg0='{self.musicListFlg0}', musicListFlg1='{self.musicListFlg1}', " f"musicListFlg2='{self.musicListFlg2}', musicListFlg3='{self.musicListFlg3}', " f"musicIndex={self.musicIndex}, musicGroup={self.musicGroup}, sheetType={self.sheetType}, " f"playTime={self.playTime}, bingoIndex={self.bingoIndex}, " f"performType={self.performType}, filterFlag={self.filterFlag})" ) class nosPlaylog(Base): __tablename__ = "nostalgiaPlaylog" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(16), unique=True) refid = Column(String(16), unique=True) musicIndex = Column(Integer, default=0) sheetType = Column(Integer, default=0) score = Column(Integer, default=0) playCount = Column(Integer, default=0) clearCount = Column(Integer, default=0) clearFlag = Column(Integer, default=0) multiCount = Column(Integer, default=0) handsMode = Column(Integer, default=0) grade = Column(Integer, default=0) recScore = Column(Integer, default=0) recPlayCount = Column(Integer, default=0) recHands = Column(Integer, default=0) recGrade = Column(Integer, default=0) def __repr__(self): return ( f"nosPlaylog(id={self.id}, " f"token='{self.token}', " f"refid='{self.refid}', " f"musicIndex={self.musicIndex}, " f"sheetType={self.sheetType}, " f"score={self.score}, " f"playCount={self.playCount}, " f"clearCount={self.clearCount}, " f"clearFlag={self.clearFlag}, " f"multiCount={self.multiCount}, " f"handsMode={self.handsMode}, " f"grade={self.grade}, " f"recScore={self.recScore}, " f"recPlayCount={self.recPlayCount}, " f"recHands={self.recHands}, " f"recGrade={self.recGrade})" ) class ddrGPProfile(Base): __tablename__ = "GrandPrixProfile" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) token = Column(String(), unique=True) refid = Column(String(16), unique=True) common = Column( String(), default="MSwwLDM3MjkwMGQsMCwwLDAsMCwwLGZmZmZmZmZmZmZmZmZmZmYsMCwwLDAsMCwwLDAs", ) option = Column( String(), default="MCwzLDAsMCwwLDAsMCwzLDAsMCwwLDAsMSwyLDAsMCwwLDEwLjAwMDAwMCwxMC4wMDAwMDAsMTAuMDAwMDAwLDEwLjAwMDAwMCwwLjAwMDAwMCwwLjAwMDAwMCwwLjAwMDAwMCwsLCwsLCwsLCwsLCw=", ) last = Column( String(), default="MSwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLCwsLCwsLCwsLCwsLA==", ) rival = Column( String(), default="MCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLDAuMDAwMDAwLCwsLCwsLCwsLCwsLA==", ) def __repr__(self): return ( f"ddrGPProfile(id={self.id}, " f"token='{self.token}', " f"refid='{self.refid}', " f"common={self.common}, " f"option={self.option}, " f"rival={self.rival})" ) class DDRGPPlaylog(Base): __tablename__ = "GrandPrixPlaylog" id = Column(Integer, primary_key=True) refid = Column(String(16)) # Stage data stage_no = Column(Integer) musicid = Column(Integer) notetype = Column(Integer) rank = Column(Integer) clearkind = Column(Integer) score = Column(Integer) exscore = Column(Integer) maxcombo = Column(Integer) life = Column(Integer) fastcount = Column(Integer) slowcount = Column(Integer) # Judge counts judge_marvelous = Column(Integer) judge_perfect = Column(Integer) judge_great = Column(Integer) judge_good = Column(Integer) judge_boo = Column(Integer) judge_miss = Column(Integer) judge_ok = Column(Integer) judge_ng = Column(Integer) # Additional data calorie = Column(Integer) ghostsize = Column(Integer) ghost = Column(String()) timestamp = Column(String()) playstyle = Column(Integer) def __repr__(self): return ( f"DDRGPPlaylog(" f"id={self.id}, " f"refid='{self.refid}', " f"stage_no={self.stage_no}, " f"musicid={self.musicid}, " f"notetype={self.notetype}, " f"rank={self.rank}, " f"clearkind={self.clearkind}, " f"score={self.score}, " f"exscore={self.exscore}, " f"maxcombo={self.maxcombo}, " f"life={self.life}, " f"fastcount={self.fastcount}, " f"slowcount={self.slowcount}, " f"judge_marvelous={self.judge_marvelous}, " f"judge_perfect={self.judge_perfect}, " f"judge_great={self.judge_great}, " f"judge_good={self.judge_good}, " f"judge_boo={self.judge_boo}, " f"judge_miss={self.judge_miss}, " f"judge_ok={self.judge_ok}, " f"judge_ng={self.judge_ng}, " f"calorie={self.calorie}, " f"ghostsize={self.ghostsize}, " f"ghost='{self.ghost}', " f"playstyle={self.playstyle})" ) class gameHashs(Base): __tablename__ = "gameHashs" id = Column(Integer, Sequence("user_id_seq"), primary_key=True) game = Column(String(), unique=True) known_hash = Column(String(), unique=True) known_resource_hash = Column(String(), unique=True) known_resource_url = Column(String(), unique=True) latest_hash = Column(String(), unique=True) latest_resource_hash = Column(String(), unique=True) latest_resource_url = Column(String(), unique=True) def __repr__(self): return ( f"gameHashs(id={self.id}, game='{self.game}',", f"knownHash='{self.known_hash}'," f"knownResourceHash='{self.known_resource_hash}'," f"knownResourceURL='{self.known_resource_url}'," f"LatestHash='{self.latest_hash}'," f"LatesResourceHash='{self.latest_resource_hash}'," f"LatesResourceURL='{self.latest_resource_url}')", ) # Function to create a database engine def create_engine_and_session(db_type="sqlite", db_name="server.db"): if db_type == "sqlite": # SQLite connection engine = create_engine( f"sqlite:///{db_name}", connect_args={"check_same_thread": False} ) elif db_type == "mysql": # MySQL connection (update with your own credentials) username = "your_username" password = "your_password" host = "localhost" engine = create_engine( f"mysql+mysqlconnector://{username}:{password}@{host}/{db_name}" ) else: raise ValueError("Unsupported database type. Use 'sqlite' or 'mysql'.") # Create all tables Base.metadata.create_all(engine) # Create a configured "Session" class Session = sessionmaker(bind=engine) return Session() def obtainGameHashs(game): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(gameHashs).filter_by(game=game).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use # /user functions/ def add_user( infinitasID, name, version, prefID, playSP, playDP, achieveSP, achieveDP, danSP, danDP, ): try: session = create_engine_and_session(db_type) new_user = infProfile( infinitasID=infinitasID, name=name, version=version, prefID=prefID, playSP=playSP, playDP=playDP, achieveSP=achieveSP, achieveDP=achieveDP, danSP=danSP, danDP=danDP, ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return True except Exception as e: print(f"Failed to Add User: {e}") return False finally: session.close() # Close the session after use def add_user_eacnet(token): try: session = create_engine_and_session(db_type) new_user = eacNetProfile( token=token, refid=int( str(random.randint(10**233, 10**400))[:16].replace( "0", str(random.randint(1, 9)) ) ), snsid=int( str(random.randint(10**233, 10**400))[:8].replace( "0", str(random.randint(1, 9)) ) ), ddrTicket=0, livelyTicket=0, ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return new_user except Exception as e: print(f"Failed to Add User: {e}") return False finally: session.close() # Close the session after use def add_user_nostalgia(name, refid, token): try: session = create_engine_and_session(db_type) new_user = nosProfile( name=name, refid=refid, token=token, playCount=0, todayPlayCount=0, oldPlayCount=0, oldTodayPlayCount=0, oldRecitalCount=0, musicListFlg0=nosProfile.musicListFlgDefault, musicListFlg1=nosProfile.musicListFlgDefault, musicListFlg2=nosProfile.musicListFlgDefault, musicListFlg3=nosProfile.musicListFlgDefault, permittedlist0=nosProfile.musicListFlgDefault, permittedlist1=nosProfile.musicListFlgDefault, permittedlist2=nosProfile.musicListFlgDefault, permittedlist3=nosProfile.musicListFlgDefault, musicIndex=0, sheetType=0, playTime=0, bingoIndex=0, performType=0, filterFlag=0, ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return new_user except Exception as e: print(f"Failed to add user: {e}") return False finally: session.close() # Close the session after use def add_user_DMGF(refid, token, did, usercode): try: session = create_engine_and_session(db_type) new_user = DMGFProfile( refid=refid, token=token, did=did, usercode=usercode, DMskill=0, DMallSkill=0, DMoldSkill=-1, DMoldAllSkill=-1, GFskill=0, GFallSkill=0, GFoldSkill=-1, GFoldAllSkill=-1, ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return new_user except Exception as e: print(f"Failed to add user: {e}") return False finally: session.close() # Close the session after use def manage_user_GP(refid, token, COMMON, OPTION, LAST, RIVAL, save): try: session = create_engine_and_session(db_type) user_profile = ( session.query(ddrGPProfile).filter_by(token=token).first() or session.query(ddrGPProfile).filter_by(refid=refid).first() ) if user_profile is None: if ( COMMON is not None and OPTION is not None and LAST is not None and RIVAL is not None ): new_user = ddrGPProfile( token=token, refid=refid, # You need to add this as well since it's a required field. common=COMMON, option=OPTION, last=LAST, rival=RIVAL, ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return new_user else: return None elif save == 0: print(f"Returning Profile") return user_profile elif save == 1: if COMMON is not None: user_profile.common = COMMON if OPTION is not None: user_profile.option = OPTION if LAST is not None: user_profile.last = LAST if RIVAL is not None: user_profile.rival = RIVAL session.commit() print(f"Updated GP Profile.") return user_profile except Exception as e: print(f"Failed to Add User: {e}") return False finally: session.close() # Close the session after use def manage_user_DMGF(refid, token, customData, favoritemusic, playinfo, game): musicFavorites = "-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1" playStyleCustom = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" try: session = create_engine_and_session(db_type) # Retrieve the user profile based on token or refid user_profile = ( session.query(DMGFProfileExt).filter_by(token=token).first() or session.query(DMGFProfileExt).filter_by(refid=refid).first() ) if user_profile is None: print("Creating new Profile") new_user = DMGFProfileExt( token=token, refid=refid, DMplaystyle=( customData["playstyle"]["#text"] if game == "DM" else playStyleCustom ), DMcustom=( customData["custom"]["#text"] if game == "DM" else playStyleCustom ), GFplaystyle=( customData["playstyle"]["#text"] if game == "GF" else playStyleCustom ), GFcustom=( customData["custom"]["#text"] if game == "GF" else playStyleCustom ), DMmusicFavorites1=( re.sub(r'"', "", favoritemusic["music_list_1"]["#text"]) if game == "DM" else musicFavorites ), DMmusicFavorites2=( re.sub(r'"', "", favoritemusic["music_list_2"]["#text"]) if game == "DM" else musicFavorites ), DMmusicFavorites3=( re.sub(r'"', "", favoritemusic["music_list_3"]["#text"]) if game == "DM" else musicFavorites ), DMlastCategory=( playinfo["last_category"]["#text"] if game == "DM" and playinfo else 0 ), DMlastMusic=( playinfo["last_musicid"]["#text"] if game == "DM" and playinfo else -1 ), DMlastSeq=( playinfo["last_seq"]["#text"] if game == "DM" and playinfo else 0 ), DMdisplayLevel=( playinfo["disp_level"]["#text"] if game == "DM" and playinfo else 0 ), GFmusicFavorites1=( re.sub(r'"', "", favoritemusic["music_list_1"]["#text"]) if game == "GF" else musicFavorites ), GFmusicFavorites2=( re.sub(r'"', "", favoritemusic["music_list_2"]["#text"]) if game == "GF" else musicFavorites ), GFmusicFavorites3=( re.sub(r'"', "", favoritemusic["music_list_3"]["#text"]) if game == "GF" else musicFavorites ), GFlastCategory=( playinfo["last_category"]["#text"] if game == "GF" and playinfo else 0 ), GFlastMusic=( playinfo["last_musicid"]["#text"] if game == "GF" and playinfo else -1 ), GFlastSeq=( playinfo["last_seq"]["#text"] if game == "GF" and playinfo else 0 ), GFdisplayLevel=( playinfo["disp_level"]["#text"] if game == "GF" and playinfo else 0 ), ) session.add(new_user) session.commit() print(f"Added new user: {new_user}") return new_user else: print(game) if game == "DM": user_profile.DMplaystyle = customData["playstyle"]["#text"] user_profile.DMcustom = customData["custom"]["#text"] user_profile.DMmusicFavorites1 = re.sub( r'"', "", favoritemusic["music_list_1"]["#text"] ) user_profile.DMmusicFavorites2 = re.sub( r'"', "", favoritemusic["music_list_2"]["#text"] ) user_profile.DMmusicFavorites3 = re.sub( r'"', "", favoritemusic["music_list_3"]["#text"] ) user_profile.DMlastCategory = playinfo["last_category"]["#text"] user_profile.DMlastMusic = playinfo["last_musicid"]["#text"] user_profile.DMlastSeq = playinfo["last_seq"]["#text"] user_profile.DMdisplayLevel = playinfo["disp_level"]["#text"] elif game == "GF": print(user_profile.GFplaystyle) print(customData["playstyle"]["#text"]) user_profile.GFplaystyle = customData["playstyle"]["#text"] user_profile.GFcustom = customData["custom"]["#text"] user_profile.GFmusicFavorites1 = re.sub( r'"', "", favoritemusic["music_list_1"]["#text"] ) user_profile.GFmusicFavorites2 = re.sub( r'"', "", favoritemusic["music_list_2"]["#text"] ) user_profile.GFmusicFavorites3 = re.sub( r'"', "", favoritemusic["music_list_3"]["#text"] ) user_profile.GFlastCategory = playinfo["last_category"]["#text"] user_profile.GFlastMusic = playinfo["last_musicid"]["#text"] user_profile.GFlastSeq = playinfo["last_seq"]["#text"] user_profile.GFdisplayLevel = playinfo["disp_level"]["#text"] session.commit() print(f"Updated {game} Profile.") return user_profile except Exception as e: print(f"Failed to Manage User Profile: {e}") return False finally: session.close() # Close the session after use def manage_user_DMGF_Details(refid, token, playinfo, game): try: session = create_engine_and_session(db_type) # Retrieve the user profile based on token or refid user_profile = ( session.query(DMGFProfileDetails).filter_by(token=token).first() or session.query(DMGFProfileDetails).filter_by(refid=refid).first() ) print(user_profile) if user_profile is None: print("Creating new Profile Details") new_user = DMGFProfileDetails( token=token, refid=refid, # Set the appropriate fields based on game type DMcabid=playinfo["cabid"]["#text"] if game == "DM" else 0, DMplay=playinfo["play"]["#text"] if game == "DM" else 0, DMplaytime=playinfo["playtime"]["#text"] if game == "DM" else 0, DMplayterm=playinfo["playterm"]["#text"] if game == "DM" else 0, DMsession_cnt=playinfo["session_cnt"]["#text"] if game == "DM" else 0, DMmatching_num=playinfo["matching_num"]["#text"] if game == "DM" else 0, DMextra_stage=playinfo["extra_stage"]["#text"] if game == "DM" else 0, DMextra_play=playinfo["extra_play"]["#text"] if game == "DM" else 0, DMextra_clear=playinfo["extra_clear"]["#text"] if game == "DM" else 0, DMencore_play=playinfo["encore_play"]["#text"] if game == "DM" else 0, DMencore_clear=playinfo["encore_clear"]["#text"] if game == "DM" else 0, DMpencore_play=playinfo["pencore_play"]["#text"] if game == "DM" else 0, DMpencore_clear=( playinfo["pencore_clear"]["#text"] if game == "DM" else 0 ), DMmax_clear_diff=( playinfo["max_clear_diff"]["#text"] if game == "DM" else 0 ), DMmax_full_diff=( playinfo["max_full_diff"]["#text"] if game == "DM" else 0 ), DMmax_exce_diff=( playinfo["max_exce_diff"]["#text"] if game == "DM" else 0 ), DMclear_num=playinfo["clear_num"]["#text"] if game == "DM" else 0, DMfull_num=playinfo["full_num"]["#text"] if game == "DM" else 0, DMexce_num=playinfo["exce_num"]["#text"] if game == "DM" else 0, DMno_num=playinfo["no_num"]["#text"] if game == "DM" else 0, DMe_num=playinfo["e_num"]["#text"] if game == "DM" else 0, DMd_num=playinfo["d_num"]["#text"] if game == "DM" else 0, DMc_num=playinfo["c_num"]["#text"] if game == "DM" else 0, DMb_num=playinfo["b_num"]["#text"] if game == "DM" else 0, DMa_num=playinfo["a_num"]["#text"] if game == "DM" else 0, DMs_num=playinfo["s_num"]["#text"] if game == "DM" else 0, DMss_num=playinfo["ss_num"]["#text"] if game == "DM" else 0, # Guitar Freaks fields GFcabid=playinfo["cabid"]["#text"] if game == "GF" else 0, GFplay=playinfo["play"]["#text"] if game == "GF" else 0, GFplaytime=playinfo["playtime"]["#text"] if game == "GF" else 0, GFplayterm=playinfo["playterm"]["#text"] if game == "GF" else 0, GFsession_cnt=playinfo["session_cnt"]["#text"] if game == "GF" else 0, GFmatching_num=playinfo["matching_num"]["#text"] if game == "GF" else 0, GFextra_stage=playinfo["extra_stage"]["#text"] if game == "GF" else 0, GFextra_play=playinfo["extra_play"]["#text"] if game == "GF" else 0, GFextra_clear=playinfo["extra_clear"]["#text"] if game == "GF" else 0, GFencore_play=playinfo["encore_play"]["#text"] if game == "GF" else 0, GFencore_clear=playinfo["encore_clear"]["#text"] if game == "GF" else 0, GFpencore_play=playinfo["pencore_play"]["#text"] if game == "GF" else 0, GFpencore_clear=( playinfo["pencore_clear"]["#text"] if game == "GF" else 0 ), GFmax_clear_diff=( playinfo["max_clear_diff"]["#text"] if game == "GF" else 0 ), GFmax_full_diff=( playinfo["max_full_diff"]["#text"] if game == "GF" else 0 ), GFmax_exce_diff=( playinfo["max_exce_diff"]["#text"] if game == "GF" else 0 ), GFclear_num=playinfo["clear_num"]["#text"] if game == "GF" else 0, GFfull_num=playinfo["full_num"]["#text"] if game == "GF" else 0, GFexce_num=playinfo["exce_num"]["#text"] if game == "GF" else 0, GFno_num=playinfo["no_num"]["#text"] if game == "GF" else 0, GFe_num=playinfo["e_num"]["#text"] if game == "GF" else 0, GFd_num=playinfo["d_num"]["#text"] if game == "GF" else 0, GFc_num=playinfo["c_num"]["#text"] if game == "GF" else 0, GFb_num=playinfo["b_num"]["#text"] if game == "GF" else 0, GFa_num=playinfo["a_num"]["#text"] if game == "GF" else 0, GFs_num=playinfo["s_num"]["#text"] if game == "GF" else 0, GFss_num=playinfo["ss_num"]["#text"] if game == "GF" else 0, ) session.add(new_user) session.commit() print(f"Added new user details: {new_user}") return new_user else: # Update existing profile based on game type if game == "DM": user_profile.DMcabid = playinfo["cabid"]["#text"] user_profile.DMplay = playinfo["play"]["#text"] user_profile.DMplaytime = playinfo["playtime"]["#text"] user_profile.DMplayterm = playinfo["playterm"]["#text"] user_profile.DMsession_cnt = playinfo["session_cnt"]["#text"] user_profile.DMmatching_num = playinfo["matching_num"]["#text"] user_profile.DMextra_stage = playinfo["extra_stage"]["#text"] user_profile.DMextra_play = playinfo["extra_play"]["#text"] user_profile.DMextra_clear = playinfo["extra_clear"]["#text"] user_profile.DMencore_play = playinfo["encore_play"]["#text"] user_profile.DMencore_clear = playinfo["encore_clear"]["#text"] user_profile.DMpencore_play = playinfo["pencore_play"]["#text"] user_profile.DMpencore_clear = playinfo["pencore_clear"]["#text"] user_profile.DMmax_clear_diff = playinfo["max_clear_diff"]["#text"] user_profile.DMmax_full_diff = playinfo["max_full_diff"]["#text"] user_profile.DMmax_exce_diff = playinfo["max_exce_diff"]["#text"] user_profile.DMclear_num = playinfo["clear_num"]["#text"] user_profile.DMfull_num = playinfo["full_num"]["#text"] user_profile.DMexce_num = playinfo["exce_num"]["#text"] user_profile.DMno_num = playinfo["no_num"]["#text"] user_profile.DMe_num = playinfo["e_num"]["#text"] user_profile.DMd_num = playinfo["d_num"]["#text"] user_profile.DMc_num = playinfo["c_num"]["#text"] user_profile.DMb_num = playinfo["b_num"]["#text"] user_profile.DMa_num = playinfo["a_num"]["#text"] user_profile.DMs_num = playinfo["s_num"]["#text"] user_profile.DMss_num = playinfo["ss_num"]["#text"] elif game == "GF": user_profile.GFcabid = playinfo["cabid"]["#text"] user_profile.GFplay = playinfo["play"]["#text"] user_profile.GFplaytime = playinfo["playtime"]["#text"] user_profile.GFplayterm = playinfo["playterm"]["#text"] user_profile.GFsession_cnt = playinfo["session_cnt"]["#text"] user_profile.GFmatching_num = playinfo["matching_num"]["#text"] user_profile.GFextra_stage = playinfo["extra_stage"]["#text"] user_profile.GFextra_play = playinfo["extra_play"]["#text"] user_profile.GFextra_clear = playinfo["extra_clear"]["#text"] user_profile.GFencore_play = playinfo["encore_play"]["#text"] user_profile.GFencore_clear = playinfo["encore_clear"]["#text"] user_profile.GFpencore_play = playinfo["pencore_play"]["#text"] user_profile.GFpencore_clear = playinfo["pencore_clear"]["#text"] user_profile.GFmax_clear_diff = playinfo["max_clear_diff"]["#text"] user_profile.GFmax_full_diff = playinfo["max_full_diff"]["#text"] user_profile.GFmax_exce_diff = playinfo["max_exce_diff"]["#text"] user_profile.GFclear_num = playinfo["clear_num"]["#text"] user_profile.GFfull_num = playinfo["full_num"]["#text"] user_profile.GFexce_num = playinfo["exce_num"]["#text"] user_profile.GFno_num = playinfo["no_num"]["#text"] user_profile.GFe_num = playinfo["e_num"]["#text"] user_profile.GFd_num = playinfo["d_num"]["#text"] user_profile.GFc_num = playinfo["c_num"]["#text"] user_profile.GFb_num = playinfo["b_num"]["#text"] user_profile.GFa_num = playinfo["a_num"]["#text"] user_profile.GFs_num = playinfo["s_num"]["#text"] user_profile.GFss_num = playinfo["ss_num"]["#text"] session.commit() print(f"Updated {game} Profile Details.") return user_profile except Exception as e: print(f"Failed to Manage User Profile Details: {e}") return False finally: session.close() # Close the session after use def add_token(infinitasID, token): try: session = create_engine_and_session(db_type) # Use raw SQL for the insert with ON CONFLICT DO NOTHING insert_query = text( """ INSERT INTO infinitasToken (infinitasID, token) VALUES (:infinitasID, :token) ON CONFLICT (infinitasID) DO NOTHING """ ) session.execute(insert_query, {"infinitasID": infinitasID, "token": token}) session.commit() print(f"Associated Token with {infinitasID}") return True except Exception as e: print(f"Failed to Add User: {e}") return False finally: session.close() # Close the session after use def fetch_users(): session = create_engine_and_session(db_type) try: # Query the database for user in session.query(infProfile).order_by(infProfile.id): print(user) except Exception as e: print(f"Failed to fetch users: {e}") finally: session.close() # Close the session after use def update_save_data(infinitasID, new_save_data, new_save_length, new_save_check): try: kbinxml_data = KBinXML(bytes.fromhex(new_save_data)).to_text() profileData = xmltodict.parse(kbinxml_data) # Ensure to parse the XML correctly session = create_engine_and_session(db_type) # Fetch the existing record user_profile = ( session.query(infProfile).filter_by(infinitasID=infinitasID).first() ) if user_profile is None: print(f"No user found with infinitasID: {infinitasID}") return False # Backup the existing saveData and saveLength user_profile.saveDataBackup = user_profile.saveData user_profile.saveLengthBackup = user_profile.saveLength user_profile.saveCheckBackup = user_profile.saveCheck session.commit() if user_profile.saveLength is None: user_profile.saveData = bytes.fromhex(new_save_data) user_profile.saveLength = new_save_length user_profile.saveCheck = new_save_check print(f"Created save data for user: {infinitasID}") else: # Update with new values user_profile.saveData = bytes.fromhex(new_save_data) user_profile.saveLength = new_save_length user_profile.saveCheck = new_save_check print(f"Updated save data for user: {infinitasID}") user_profile.playSP = int( profileData["pdata"]["player"]["play_num_sp"]["#text"] ) user_profile.playDP = int( profileData["pdata"]["player"]["play_num_dp"]["#text"] ) user_profile.danSP = int(profileData["pdata"]["player"]["grade_id_sp"]["#text"]) user_profile.danDP = int(profileData["pdata"]["player"]["grade_id_dp"]["#text"]) # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update save data: {e}") return False finally: session.close() # Close the session after use def update_save_data_bits(infinitasID, bits): try: session = create_engine_and_session(db_type) # Fetch the existing record user_profile = ( session.query(infProfile).filter_by(infinitasID=infinitasID).first() ) if user_profile is None: print(f"No user found with infinitasID: {infinitasID}") return False print(bits) user_profile.bits = int(bits) # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update save data: {e}") return False finally: session.close() # Close the session after use def manage_ghost_data( infinitasID, name, score, danRank, prefecture, musicID, noteID, ghost, ghostCheck, ghostSize, flip, assist, arrange1, arrange0, clear_flag, ): try: session = create_engine_and_session( db_type ) # Assuming db_type is defined elsewhere # Fetch existing ghost data based on infinitasID, musicID, and noteID existing_ghost_data = ( session.query(infGhostData) .filter_by(infinitasID=infinitasID, musicID=musicID, noteID=noteID) .first() ) if existing_ghost_data and existing_ghost_data.score > int(score): # Update the existing ghost data existing_ghost_data.name = name existing_ghost_data.score = score existing_ghost_data.danRank = danRank existing_ghost_data.prefecture = prefecture existing_ghost_data.ghost = ghost existing_ghost_data.ghostCheck = ghostCheck existing_ghost_data.ghostSize = ghostSize existing_ghost_data.flip = flip existing_ghost_data.assist = assist existing_ghost_data.arrange1 = arrange1 existing_ghost_data.arrange0 = arrange0 existing_ghost_data.clear_flag = clear_flag session.commit() print( f"Updated existing ghost data for infinitasID: {infinitasID}, musicID: {musicID}, noteID: {noteID}" ) elif not existing_ghost_data: # Create new ghost data if it doesn't exist new_ghost_data = infGhostData( infinitasID=infinitasID, name=name, score=score, danRank=danRank, prefecture=prefecture, musicID=musicID, noteID=noteID, ghost=ghost, ghostCheck=ghostCheck, ghostSize=ghostSize, flip=flip, assist=assist, arrange1=arrange1, arrange0=arrange0, clear_flag=clear_flag, ) session.add(new_ghost_data) session.commit() print( f"Added new ghost data for infinitasID: {infinitasID}, musicID: {musicID}, noteID: {noteID}" ) return True except Exception as e: print(f"Failed to Add or Update Ghost Data: {e}") return False finally: session.close() # Close the session after use def manage_music_data(infinitasID, musicID, noteID, score, missCount, ClearFlag): try: session = create_engine_and_session( db_type ) # Assuming db_type is defined elsewhere scores = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] missCounts = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] ClearFlags = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] clearAmounts = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] playCounts = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] scores[int(noteID)] = int(score) missCounts[int(noteID)] = int(missCount) ClearFlags[int(noteID)] = int(ClearFlag) playCounts[int(noteID)] = 1 # Fetch existing ghost data based on infinitasID, musicID, and noteID print("checking for existing data") existing_music_data = ( session.query(InfinitasPlayData) .filter_by(infinitasID=infinitasID, musicID=musicID) .first() ) userInfinitasProfile = ( session.query(infProfile).filter_by(infinitasID=infinitasID).first() ) userInfinitasProfile.totalPlays = userInfinitasProfile.totalPlays + 1 if ClearFlags[int(noteID)] > 1: # Change here print("cleared") clearAmounts[int(noteID)] = 1 userInfinitasProfile.totalClears = userInfinitasProfile.totalClears + 1 if existing_music_data: print(existing_music_data) # Update the existing ghost data scrs = json.loads(existing_music_data.score) print("checking for up score") if scrs[int(noteID)] < int(score): # If the score is higher scrs[int(noteID)] = int(score) # Correctly update the score existing_music_data.score = json.dumps(scrs) # Save as JSON string msCnt = json.loads(existing_music_data.missCount) print("checking for miss drop") if msCnt[int(noteID)] > int(missCount): msCnt[int(noteID)] = int(missCount) # Update the miss count existing_music_data.missCount = json.dumps(msCnt) # Save as JSON string print("checking for clear flag") if int(ClearFlag) > 1: # if clearflag doesn't mean a miss clrFlg = json.loads(existing_music_data.clearFlag) clrAmt = json.loads(existing_music_data.clearAmount) plyCnt = json.loads(existing_music_data.playCount) if clrFlg[int(noteID)] < int(ClearFlag): clrFlg[int(noteID)] = int(ClearFlag) existing_music_data.clearFlag = json.dumps( clrFlg ) # Save as JSON string clrAmt[int(noteID)] += 1 # Increment the clear amount existing_music_data.clearAmount = json.dumps( clrAmt ) # Save as JSON string plyCnt[int(noteID)] += 1 # Increment the clear amount existing_music_data.playCount = json.dumps( plyCnt ) # Save as JSON string print( f"Updated existing Player Music Player Data for infinitasID: {infinitasID}, musicID: {musicID}, noteID: {noteID}" ) else: # Create new ghost data if it doesn't exist newPlayData = InfinitasPlayData( infinitasID=infinitasID, musicID=musicID, missCount=json.dumps(missCounts), # Save as JSON string playCount=json.dumps(playCounts), # Save as JSON string clearAmount=json.dumps(clearAmounts), # Save as JSON string clearFlag=json.dumps(ClearFlags), # Save as JSON string score=json.dumps(scores), # Save as JSON string ) session.add(newPlayData) print( f"Added new Player Music Player Data for infinitasID: {infinitasID}, musicID: {musicID}, noteID: {noteID}" ) session.commit() return True except Exception as e: print(f"Failed to Add or Update Player Music Player Data: {e}") return False finally: session.close() # Close the session after use def update_save_data_consumables(infinitasID, type, amount): try: session = create_engine_and_session(db_type) # Fetch the existing record user_profile = ( session.query(infProfile).filter_by(infinitasID=infinitasID).first() ) user_item = session.query(infItems).filter_by(infinitasID=infinitasID).first() if user_item is None: user_item = infItems(infinitasID=infinitasID) session.add(user_item) if user_profile is None: print(f"No user found with infinitasID: {infinitasID}") return False elif type is None or amount is None or user_item is None: print("/!\\ Missing Type and or Amount, or failed to find user_item row") return False elif type == 0: if user_profile.bits < int(amount): return False # User doesn't have enough bits to continue unlocking. elif type == 1: if user_item.TicketsPaid > 0: user_item.TicketsPaid = user_item.TicketsPaid - 1 elif user_item.TicketsFree > 0: user_item.TicketsFree = user_item.TicketsFree - 1 else: return False # User doesn't have enough tickets, they need more to continue. elif type == 2: if user_item.lDiscs > 0: user_item.lDiscs = user_item.lDiscs - 1 else: return False # User doesn't have enough lDiscs, they need more to continue. elif type == 3: if user_item.TicketsPaid > 0: user_item.TicketsPaid = user_item.TicketsPaid - 1 user_item.lDiscs = user_item.lDiscs + 5 elif user_item.TicketsFree > 0: user_item.TicketsFree = user_item.TicketsFree - 1 user_item.lDiscs = user_item.lDiscs + 5 else: return False # User doesn't have enough tickets, they need more to continue. # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update save data: {e}") return False finally: session.close() # Close the session after use def update_save_data_consumablesEAC(token, game, goods_id): try: session = create_engine_and_session(db_type) # Fetch the existing record user_profile = session.query(eacNetProfile).filter_by(token=token).first() if user_profile is None: print(f"No user found with token: {token}") return False elif game is None or goods_id is None: print("/!\\ Missing Type and or Amount, or failed to find user_item row") return False elif game == "ddr": match goods_id: case "G0000001": print(user_profile.ddrTicket) print(user_profile.ddrTicket - 6) print((user_profile.ddrTicket - 6) >= 0) if (user_profile.ddrTicket - 6) >= 0: user_profile.ddrTicket += -6 else: return False case _: if (user_profile.ddrTicket - 5) >= 0: user_profile.ddrTicket += -5 else: return False elif game == "popn-music": match goods_id: case "G0000001": if (user_profile.livelyTicket - 6) >= 0: user_profile.livelyTicket -= 6 # Deduct 6 tickets else: return False # Not enough tickets case ( "G0000002" | "G0000003" | "G0000004" | "G0000005" | "G0000006" | "G0000007" | "G0000008" | "G0000009" | "G0000010" | "G0000011" ): if (user_profile.livelyTicket - 5) >= 0: user_profile.livelyTicket -= 5 # Deduct 5 tickets else: return False # Not enough tickets case ( "GS000004" | "GS000005" | "GS000006" | "GS000007" | "GS000008" | "GS000009" | "GS000010" | "GS000011" ): if (user_profile.livelyTicket - 2) >= 0: user_profile.livelyTicket -= 2 # Deduct 2 tickets else: return False # Not enough tickets case _: return False # Invalid goods_id # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update save data: {e}") return False finally: session.close() # Close the session after use def update_unlock_status(infinitasID, musicID, kind, note_bit): try: session = create_engine_and_session(db_type) # Fetch the existing record user_profile = ( session.query(infUnlocks) .filter_by(infinitasID=infinitasID, musicID=musicID) .first() ) if user_profile is None: print(f"Unlocking SongID {musicID} for infinitasID: {infinitasID}") new_song_unlocked = infUnlocks( infinitasID=infinitasID, musicID=musicID, type=kind, note_bit=note_bit ) session.add(new_song_unlocked) else: # Update with new values user_profile.note_bit = int(note_bit) + int(user_profile.note_bit) print(f"Updated musicID {musicID} unlock data for user: {infinitasID}") # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update musicID {musicID} unlock data: {e}") return False finally: session.close() # Close the session after use def nostalgia_update_musicList( token, refid, musicListFlg0, musicListFlg1, musicListFlg2, musicListFlg3 ): try: session = create_engine_and_session(db_type) # Fetch the existing record user_profile = ( session.query(nosProfile).filter_by(token=token).first() or session.query(nosProfile).filter_by(refid=refid).first() ) if user_profile is None: return False else: # Update with new values user_profile.musicListFlg0 = musicListFlg0 user_profile.musicListFlg1 = musicListFlg1 user_profile.musicListFlg2 = musicListFlg2 user_profile.musicListFlg3 = musicListFlg3 print(f"Updated musicList Flags.") # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update musicList Flags: {e}") return False finally: session.close() # Close the session after use def nostalgia_update_playlog( token, refid, musicIndex, sheetType, score, clearFlag, multiCount, handsMode, grade, playStyle, ): try: session = create_engine_and_session(db_type) # Fetch the existing record user_playlog = ( session.query(nosPlaylog).filter_by(token=token).first() or session.query(nosPlaylog).filter_by(refid=refid).first() ) if user_playlog is None: print(f"Creating new playlog for token: {token}, refid: {refid}") if playStyle == 1: new_playlog = nosPlaylog( token=token, refid=refid, musicIndex=musicIndex, sheetType=sheetType, clearFlag=clearFlag, clearCount=clearFlag, multiCount=multiCount, recScore=score, recPlayCount=1, recHandsMode=handsMode, recGrade=grade, ) else: new_playlog = nosPlaylog( token=token, refid=refid, musicIndex=musicIndex, sheetType=sheetType, clearFlag=clearFlag, clearCount=clearFlag, multiCount=multiCount, score=score, playCount=1, handsMode=handsMode, grade=grade, ) session.add(new_playlog) else: # Update with new values user_playlog.musicIndex = musicIndex user_playlog.sheetType = sheetType user_playlog.clearCount += clearFlag user_playlog.multiCount = multiCount if user_playlog.clearFlag < clearFlag: user_playlog.clearFlag = clearFlag if playStyle == 1: user_playlog.recScore = score user_playlog.recPlayCount += user_playlog.recPlayCount user_playlog.recHandsMode = handsMode user_playlog.recGrade = grade else: user_playlog.score = score user_playlog.playCount += user_playlog.playCount user_playlog.handsMode = handsMode user_playlog.grade = grade # Optionally, handle playStyle if needed in the model print(f"Updated playlog for token: {token}, refid: {refid}") # Commit the changes session.commit() return True except Exception as e: print(f"Failed to update playlog for token: {token}, refid: {refid}: {e}") return False finally: session.close() # Close the session after use # DMGF Playlog here please def update_DMGF_playlog(refid, token, stage_data, game): try: session = create_engine_and_session(db_type) new_playlog = DMGFPlaylog( refid=refid, token=token, game=game, date_ms=stage_data["date_ms"]["#text"], stage_no=stage_data["stage_no"]["#text"], musicid=stage_data["musicid"]["#text"], seq=stage_data["seq"]["#text"], skill=stage_data["skill"]["#text"], new_skill=stage_data["new_skill"]["#text"], clear=stage_data["clear"]["#text"], auto_clear=stage_data["auto_clear"]["#text"], fullcombo=stage_data["fullcombo"]["#text"], excellent=stage_data["excellent"]["#text"], medal=stage_data["medal"]["#text"], perc=stage_data["perc"]["#text"], new_perc=stage_data["new_perc"]["#text"], rank=stage_data["rank"]["#text"], score=stage_data["score"]["#text"], combo=stage_data["combo"]["#text"], max_combo_perc=stage_data["max_combo_perc"]["#text"], flags=stage_data["flags"]["#text"], phrase_combo_perc=stage_data["phrase_combo_perc"]["#text"], perfect=stage_data["perfect"]["#text"], great=stage_data["great"]["#text"], good=stage_data["good"]["#text"], ok=stage_data["ok"]["#text"], miss=stage_data["miss"]["#text"], perfect_perc=stage_data["perfect_perc"]["#text"], great_perc=stage_data["great_perc"]["#text"], good_perc=stage_data["good_perc"]["#text"], ok_perc=stage_data["ok_perc"]["#text"], miss_perc=stage_data["miss_perc"]["#text"], meter=stage_data["meter"]["#text"], meter_prog=stage_data["meter_prog"]["#text"], before_meter=stage_data["before_meter"]["#text"], before_meter_prog=stage_data["before_meter_prog"]["#text"], is_new_meter=stage_data["is_new_meter"]["#text"], phrase_data_num=stage_data["phrase_data_num"]["#text"], phrase_addr=stage_data["phrase_addr"]["#text"], phrase_type=stage_data["phrase_type"]["#text"], phrase_status=stage_data["phrase_status"]["#text"], phrase_end_addr=stage_data["phrase_end_addr"]["#text"], ) session.add(new_playlog) session.commit() return True except Exception as e: print(f"Failed to update playlog: {e}") return False finally: session.close() def ddrgp_insert_playlog( refid, stage_no, musicid, notetype, rank, clearkind, score, exscore, maxcombo, life, fastcount, slowcount, judge_marvelous, judge_perfect, judge_great, judge_good, judge_boo, judge_miss, judge_ok, judge_ng, calorie, ghostsize, ghost, timestamp, playstyle, ): try: session = create_engine_and_session(db_type) # Check if a playlog entry with the given timestamp already exists for the user existing_playlog = ( session.query(DDRGPPlaylog) .filter_by(refid=refid, timestamp=timestamp) .first() ) if existing_playlog is None: print(f"Creating new playlog for refid: {refid}, timestamp: {timestamp}") new_playlog = DDRGPPlaylog( refid=refid, stage_no=stage_no, musicid=musicid, notetype=notetype, rank=rank, clearkind=clearkind, score=score, exscore=exscore, maxcombo=maxcombo, life=life, fastcount=fastcount, slowcount=slowcount, judge_marvelous=judge_marvelous, judge_perfect=judge_perfect, judge_great=judge_great, judge_good=judge_good, judge_boo=judge_boo, judge_miss=judge_miss, judge_ok=judge_ok, judge_ng=judge_ng, calorie=calorie, ghostsize=ghostsize, ghost=ghost, timestamp=timestamp, playstyle=playstyle, ) session.add(new_playlog) session.commit() print( f"New playlog entry created for refid: {refid}, timestamp: {timestamp}" ) else: print( f"Playlog entry for refid: {refid}, timestamp: {timestamp} already exists." ) return True except Exception as e: print( f"Failed to insert playlog for refid: {refid}, timestamp: {timestamp}: {e}" ) return False finally: session.close() # Close the session after use # Web UI Stuff def updateCustomizationsWeb(token, custom, otherCustom): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(infToken) .filter_by(token=token) .first() # Use filter_by to find the token ) items = session.query(infItems).filter_by(infinitasID=user.infinitasID).first() items.customizations = custom items.otherCustomizations = otherCustom session.commit() return True except Exception as e: print(f"Failed to fetch token: {e}") return False finally: session.close() # Close the session after use # / database lookup / def getrIDfromToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(eacNetProfile).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getInfIDByToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(infToken).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getEacnetProfilebyToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(eacNetProfile).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getNostalgiaProfilebyToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(nosProfile).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getDMGFProfilebyToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(DMGFProfile).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getDMGFProfileExtbyToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(DMGFProfileExt).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getDMGFProfileDetailsbyToken(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(DMGFProfileDetails).filter_by(token=token).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getDMGFPlaylogbyToken(token, game): """Get playlog entries for a specific token and game type""" session = create_engine_and_session(db_type) if token is None: print(f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR PLAYLOG\nToken: {token}") return None try: # Query the database for all playlogs matching token and game type playlogs = ( session.query(DMGFPlaylog) .filter_by(token=token, game=game) .order_by( DMGFPlaylog.musicid, desc(DMGFPlaylog.excellent), # Prioritize excellent clears first desc(DMGFPlaylog.fullcombo), # Then full combos desc(DMGFPlaylog.clear), # Then regular clears desc(DMGFPlaylog.score), # Finally, highest score ) .all() ) # Use .all() to get all matching entries return playlogs # Returns list of playlogs or empty list if none found except Exception as e: print(f"Failed to fetch Playlogs: {e}") return None finally: session.close() def getDDRGPPlaylogbyRefid(refid): """Get playlog entries for a specific token and game type""" session = create_engine_and_session(db_type) if refid is None: print(f"/\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR PLAYLOG\nrefid: {refid}") return None try: # Query the database for all playlogs matching refid and game type playlogs = ( session.query(DDRGPPlaylog) .filter_by(refid=refid) .order_by( DDRGPPlaylog.musicid, asc(DDRGPPlaylog.clearkind), asc(DDRGPPlaylog.rank), ) .all() ) # Use .all() to get all matching entries # Convert the playlogs to dictionaries playlogs_dict = [playlog.__dict__ for playlog in playlogs] return playlogs_dict # Returns list of dictionaries or empty list if none found except Exception as e: print(f"Failed to fetch Playlogs: {e}") return None finally: session.close() def getNostalgiaProfilebyRefID(refID): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(nosProfile).filter_by(refid=refID).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getNostalgiaMusicData(token): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = session.query(nosPlaylog).filter_by( token=token ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch Profile Music Data: {e}") return None finally: session.close() # Close the session after use def getItemsbyInfID(infID): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(infItems).filter_by(infinitasID=infID).first() ) # Use filter_by to find the token if user is None: print("cant find the user") user = infItems(infinitasID=infID) session.add(user) session.commit() return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch token: {e}") return None finally: session.close() # Close the session after use def getProfileByInfID(infID): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(infProfile).filter_by(infinitasID=infID).first() ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch Profile: {e}") return None finally: session.close() # Close the session after use def getInfIDMusicData(infID): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = session.query(InfinitasPlayData).filter_by( infinitasID=infID ) # Use filter_by to find the token return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch Profile Music Data: {e}") return None finally: session.close() # Close the session after use def getInfIDMusicDataMusicID(infID, musicID): session = create_engine_and_session(db_type) try: # Query the database for the token and get the first result user = ( session.query(InfinitasPlayData) .filter_by(infinitasID=infID, musicID=musicID) .first() ) # Use filter_by to find the token print(user) return user # This will return the user object or None if not found except Exception as e: print(f"Failed to fetch Profile Music Data: {e}") return None finally: session.close() # Close the session after use def getGhostDataFromInfIDandCheckSum( musicID=None, difficulty=None, infID=None, checksum=None ): session = create_engine_and_session(db_type) if musicID is None or difficulty is None or infID is None: print( f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR GHOSTS\nMusicID: {musicID}\nDifficulty: {difficulty}\nInfinitasID: {infID}\nGhost Checksum: {checksum}" ) return None try: # Query the database for the token and get the first result if checksum is None: ghost = ( session.query(infGhostData) .filter_by(musicID=musicID, noteID=difficulty, infinitasID=infID) .first() # Use filter_by to find the token ) else: ghost = ( session.query(infGhostData) .filter_by( musicID=musicID, noteID=difficulty, infinitasID=infID, ghostCheck=checksum, ) .first() # Use filter_by to find the token ) return ghost # This will return the ghost, or `None`` if not found except Exception as e: print(f"Failed to fetch Profile: {e}") return None finally: session.close() # Close the session after use def getAllGhostDataFromInfID(infID=None): session = create_engine_and_session(db_type) if infID is None: print( f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR GHOSTS\nInfinitasID: {infID}" ) return None try: # Query the database for the token and get the first result ghost = ( session.query(infGhostData) .filter_by(infinitasID=infID) .order_by(infGhostData.score.desc()) ) # Use filter_by to find the token return ghost # This will return the ghost, or `None`` if not found except Exception as e: print(f"Failed to fetch Profile: {e}") return None finally: session.close() # Close the session after use def randomizeGhost( musicID=None, difficulty=None, infID=None, danRank=None, prefecture=None ): session = create_engine_and_session(db_type) if musicID is None or difficulty is None or infID is None: print( f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR GHOSTS\nMusicID: {musicID}\nDifficulty: {difficulty}\nInfinitasID: {infID}" ) return None try: ghost = session.query(infGhostData).filter_by( musicID=musicID, noteID=difficulty ) # Query the database for the token and get the first result if prefecture and int(prefecture) != -1: ghost = ghost.filter_by(prefecture=int(prefecture)) if danRank and int(danRank) != -1: ghost = ghost.filter_by(danRank=int(danRank)) ghost = ghost.order_by(func.random()).first() # Use filter_by to find the token return ghost # This will return the ghost, or `None` if not found except Exception as e: print(f"Failed to fetch Ghost Data: {e}") return None finally: session.close() # Close the session after use def getAllUnlockDataFromInfID(infID=None): session = create_engine_and_session(db_type) if infID is None: print( f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR GHOSTS\nInfinitasID: {infID}" ) return None try: # Query the database for the token and get the first result unlocks = session.query(infUnlocks).filter_by( infinitasID=infID ) # Use filter_by to find the token return unlocks # This will return the ghost, or `None`` if not found except Exception as e: print(f"Failed to fetch Profile: {e}") return None finally: session.close() # Close the session after use def getRivalDataFromInfID(infID=None): session = create_engine_and_session(db_type) if infID is None: print( f"/!\\ ARGUMENT CHECK FAILED, CANNOT SEARCH FOR RIVAL DATA\nInfinitasID: {infID}" ) return None try: # Query the database for the token and get the first result rival = ( session.query(infRivalData).filter_by(infinitasID=infID).first() ) # Use first() to get the first result if rival is None: print("No Rival Data Found. Generating Default Rival Data for User.") rival = infRivalData(infinitasID=infID, spRivals="[]", dpRivals="[]") session.add(rival) session.commit() return rival # This will return the rival data or None if not found except Exception as e: print(f"Failed to fetch Profile: {e}") return None finally: session.close() # Close the session after use # Add after line 414 where you marked "Define DMGF Playlog here please"