add live status notify
This commit is contained in:
35
db.py
Normal file
35
db.py
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import mysql.connector
|
||||
import schedule
|
||||
|
||||
class Room:
|
||||
def __init__(self, room_id, liver_uid, liver_name):
|
||||
self.room_id = room_id
|
||||
self.liver_uid = liver_uid
|
||||
self.liver_name = liver_name
|
||||
|
||||
|
||||
rooms = {}
|
||||
|
||||
connection = mysql.connector.connect(
|
||||
host="mysql",
|
||||
database="live_log",
|
||||
user="live_log",
|
||||
password="!36z@Jd6LM@uxktq",
|
||||
)
|
||||
|
||||
|
||||
def flush_room_info():
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"SELECT room_id, liver_uid, liver_name FROM liver_current_name")
|
||||
for room_id, liver_uid, liver_name in cursor.fetchall():
|
||||
rooms[room_id] = Room(room_id, liver_uid, liver_name)
|
||||
|
||||
|
||||
def get_room(room_id) -> Room:
|
||||
return rooms.get(room_id, Room(room_id, 0, str(room_id)))
|
||||
|
||||
|
||||
flush_room_info()
|
||||
schedule.every(1).days.do(flush_room_info)
|
||||
Reference in New Issue
Block a user