このコミットが含まれているのは:
@@ -81,6 +81,7 @@ class User (Model):
|
||||
class Video (Model):
|
||||
id: int
|
||||
code: str
|
||||
user_id: int | None
|
||||
title: str
|
||||
description: str
|
||||
uploaded_at: datetime
|
||||
@@ -88,6 +89,14 @@ class Video (Model):
|
||||
|
||||
__timestamps__ = False
|
||||
|
||||
@property
|
||||
def user (
|
||||
self,
|
||||
) -> User | None:
|
||||
if self.user_id is None:
|
||||
return None
|
||||
return self.belongs_to (User)
|
||||
|
||||
@property
|
||||
def video_histories (
|
||||
self,
|
||||
|
||||
@@ -27,6 +27,7 @@ def main (
|
||||
deleted_at = row.deleted_at.date () if row.deleted_at else None
|
||||
video: VideoDict = { 'id': row.id,
|
||||
'code': row.code,
|
||||
'user': row.user.code if row.user else None,
|
||||
'title': row.title,
|
||||
'description': row.description,
|
||||
'tags': [],
|
||||
@@ -52,6 +53,7 @@ class DbConfig (TypedDict):
|
||||
class VideoDict (TypedDict):
|
||||
id: int
|
||||
code: str
|
||||
user: str | None
|
||||
title: str
|
||||
description: str
|
||||
tags: list[str]
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE `videos` ADD `user_id` BIGINT NULL DEFAULT NULL COMMENT 'ユーザ Id.' AFTER `code`;
|
||||
ALTER TABLE `videos` ADD INDEX(`user_id`);
|
||||
ALTER TABLE `videos` ADD FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
+11
@@ -55,8 +55,16 @@ def update_tables (
|
||||
|
||||
for datum in api_data:
|
||||
tag_names: list[str] = datum['tags'].split ()
|
||||
user: User | None = None
|
||||
if datum['userId']:
|
||||
user = User.where('code', str (datum['userId'])).first ()
|
||||
if user is None:
|
||||
user = User ()
|
||||
user.code = str (datum['userId'])
|
||||
user.save ()
|
||||
video = Video ()
|
||||
video.code = datum['contentId']
|
||||
video.user_id = user.id if user else None
|
||||
video.title = datum['title']
|
||||
video.description = datum['description'] or ''
|
||||
video.uploaded_at = datetime.fromisoformat (datum['startTime'])
|
||||
@@ -199,6 +207,7 @@ def search_nico_by_tags (
|
||||
'targets': 'tagsExact',
|
||||
'_sort': '-viewCounter',
|
||||
'fields': ('contentId,'
|
||||
'userId,'
|
||||
'title,'
|
||||
'tags,'
|
||||
'description,'
|
||||
@@ -220,6 +229,7 @@ def search_nico_by_tags (
|
||||
video_data = fetch_video_data (video.code)['data']
|
||||
result_data.append ({
|
||||
'contentId': video.code,
|
||||
'userId': video_data['video']['userId'],
|
||||
'title': video_data['video']['title'],
|
||||
'tags': ' '.join (map (lambda t: t['name'],
|
||||
video_data['tag']['items'])),
|
||||
@@ -243,6 +253,7 @@ class VideoSearchParam (TypedDict):
|
||||
|
||||
class VideoResult (TypedDict):
|
||||
contentId: str
|
||||
userId: int | None
|
||||
title: str
|
||||
tags: str
|
||||
description: str | None
|
||||
|
||||
新しい課題から参照
ユーザをブロックする