update database to use sqlalchemy

This commit is contained in:
SumGuyV5 committed 2026-09-17 03:57:44 +00:00
1 parent 2773200a94
commit 61fe9eca25
9 files changed
+267 -170

No files matched your search

+38 -41
View File
@@ -7,6 +7,7 @@ from twitchAPI.type import VideoType
import package.twitch.config as config
from package.config import DB as DB
from package.database.database import TwitchVideo
GAME_CACHE = {} # Local cache dictionary to store game_id -> game_name mapping
@@ -101,20 +102,20 @@ async def get_streamer_vods() -> list:
except ValueError:
clean_game_id = 0
vod_data = {
"id": v.id,
"title": v.title,
"created_at": str(v.published_at),
"view_count": int(v.view_count) if v.view_count else 0,
"duration": v.duration,
"url": v.url,
"thumbnail_url": v.thumbnail_url,
"game_id": clean_game_id,
"game_name": game_name,
"stream_id": str(v.stream_id) if v.stream_id else "0",
"creator_name": config.CHANNEL_NAME,
"clip_is": False,
}
vod_data = TwitchVideo()
vod_data.id = v.id
vod_data.title = v.title
vod_data.created_at = str(v.published_at)
vod_data.view_count = int(v.view_count) if v.view_count else 0
vod_data.duration = v.duration
vod_data.url = v.url
vod_data.thumbnail_url = v.thumbnail_url
vod_data.game_id = clean_game_id
vod_data.game_name = game_name
vod_data.stream_id = str(v.stream_id) if v.stream_id else "0"
vod_data.creator_name = config.CHANNEL_NAME
vod_data.clip_is = False
all_vods.append(vod_data)
print(f"Collected VOD: {v.title} | Category: {game_name} ({v.duration})")
@@ -131,20 +132,20 @@ async def get_streamer_clips() -> list:
async for c in clip_generator:
game_name = await get_game_name_by_id(c.game_id)
clip_data = {
"id": c.id,
"title": c.title,
"created_at": str(c.created_at),
"view_count": int(c.view_count) if c.view_count else 0,
"duration": c.duration,
"url": c.url,
"thumbnail_url": c.thumbnail_url,
"game_id": c.game_id,
"game_name": game_name,
"stream_id": "0",
"creator_name": c.creator_name,
"clip_is": True,
}
clip_data = TwitchVideo()
clip_data.id = c.id
clip_data.title = c.title
clip_data.created_at = str(c.created_at)
clip_data.view_count = int(c.view_count) if c.view_count else 0
clip_data.duration = c.duration
clip_data.url = c.url
clip_data.thumbnail_url = c.thumbnail_url
clip_data.game_id = c.game_id
clip_data.game_name = game_name
clip_data.stream_id = "0"
clip_data.creator_name = c.creator_name
clip_data.clip_is = True
all_clips.append(clip_data)
print(f"Collected clip: {c.title} | Category: {game_name} ({c.view_count} views)")
@@ -157,26 +158,22 @@ async def video_info():
vods_list = await get_streamer_vods()
for v in vods_list:
DB.insert_video_record(
v['id'], v['title'], v['created_at'], v['view_count'], v['duration'],
v['url'], v['thumbnail_url'], v['game_id'], v['game_name'],
v['stream_id'], v['creator_name'], v['clip_is']
)
DB.insert(v)
if vods_list:
print(f"Recent VOD: '{vods_list[0]['title']}'")
print("====================================================")
print(f"Recent VOD: '{vods_list[0].title}'")
print("====================================================")
clips_list = await get_streamer_clips()
for v in clips_list:
DB.insert_video_record(
v['id'], v['title'], v['created_at'], v['view_count'], v['duration'],
v['url'], v['thumbnail_url'], v['game_id'], v['game_name'],
v['stream_id'], v['creator_name'], v['clip_is']
)
DB.insert(v)
if clips_list:
print(f"Recent VOD: '{clips_list[0]['title']}'")
print("====================================================")
print(f"Recent VOD: '{clips_list[0].title}'")
print("====================================================")
if __name__ == "__main__":
asyncio.run(video_info())