mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-04 13:17:27 +08:00
Code refactoring
- Code refactoring - Fix a bug that the other player will not become the host of the room at once, when the player disconnect in link play. > Maybe add many unknown bugs. XD > The song database `arcsong.db` will not used in the future. You can use a tool in `tool` folder to import old data.
This commit is contained in:
60
tools/update_song.py
Normal file
60
tools/update_song.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import sqlite3
|
||||
|
||||
class Connect():
|
||||
# 数据库连接类,上下文管理
|
||||
|
||||
def __init__(self, file_path='./arcaea_database.db'):
|
||||
"""
|
||||
数据库连接,默认连接arcaea_database.db\
|
||||
接受:文件路径\
|
||||
返回:sqlite3连接操作对象
|
||||
"""
|
||||
self.file_path = file_path
|
||||
|
||||
def __enter__(self):
|
||||
self.conn = sqlite3.connect(self.file_path)
|
||||
self.c = self.conn.cursor()
|
||||
return self.c
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
|
||||
if exc_type is not None:
|
||||
if self.conn:
|
||||
self.conn.rollback()
|
||||
|
||||
if self.conn:
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def insert(cursor, song_id, name, a, b, c, d):
|
||||
'''Insert a new song into database.'''
|
||||
cursor.execute(
|
||||
'''select exists(select * from chart where song_id=?)''', (song_id, ))
|
||||
if cursor.fetchone()[0]:
|
||||
return None
|
||||
cursor.execute(
|
||||
'''insert into chart values (?,?,?,?,?,?)''', (song_id, name, a, b, c, d))
|
||||
|
||||
|
||||
def old_to_new():
|
||||
'''Update old database to new database.'''
|
||||
with Connect('./arcsong.db') as c:
|
||||
c.execute(
|
||||
'''select sid, name_en, rating_pst, rating_prs, rating_ftr, rating_byn from songs''')
|
||||
data = c.fetchall()
|
||||
with Connect() as c:
|
||||
for x in data:
|
||||
insert(c, x[0], x[1], x[2], x[3], x[4], x[5])
|
||||
|
||||
|
||||
def main():
|
||||
old_to_new()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
print('Done.')
|
||||
input()
|
||||
exit()
|
||||
Reference in New Issue
Block a user