投稿者情報追加(#17) #18
@@ -81,6 +81,7 @@ class User (Model):
|
|||||||
class Video (Model):
|
class Video (Model):
|
||||||
id: int
|
id: int
|
||||||
code: str
|
code: str
|
||||||
|
user_id: int | None
|
||||||
title: str
|
title: str
|
||||||
description: str
|
description: str
|
||||||
uploaded_at: datetime
|
uploaded_at: datetime
|
||||||
@@ -88,6 +89,14 @@ class Video (Model):
|
|||||||
|
|
||||||
__timestamps__ = False
|
__timestamps__ = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user (
|
||||||
|
self,
|
||||||
|
) -> User | None:
|
||||||
|
if self.user_id is None:
|
||||||
|
return None
|
||||||
|
return self.belongs_to (User)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def video_histories (
|
def video_histories (
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ def main (
|
|||||||
deleted_at = row.deleted_at.date () if row.deleted_at else None
|
deleted_at = row.deleted_at.date () if row.deleted_at else None
|
||||||
video: VideoDict = { 'id': row.id,
|
video: VideoDict = { 'id': row.id,
|
||||||
'code': row.code,
|
'code': row.code,
|
||||||
|
'user': row.user.code if row.user else None,
|
||||||
'title': row.title,
|
'title': row.title,
|
||||||
'description': row.description,
|
'description': row.description,
|
||||||
'tags': [],
|
'tags': [],
|
||||||
@@ -52,6 +53,7 @@ class DbConfig (TypedDict):
|
|||||||
class VideoDict (TypedDict):
|
class VideoDict (TypedDict):
|
||||||
id: int
|
id: int
|
||||||
code: str
|
code: str
|
||||||
|
user: str | None
|
||||||
title: str
|
title: str
|
||||||
description: str
|
description: str
|
||||||
tags: list[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:
|
for datum in api_data:
|
||||||
tag_names: list[str] = datum['tags'].split ()
|
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 = Video ()
|
||||||
video.code = datum['contentId']
|
video.code = datum['contentId']
|
||||||
|
video.user_id = user.id if user else None
|
||||||
video.title = datum['title']
|
video.title = datum['title']
|
||||||
video.description = datum['description'] or ''
|
video.description = datum['description'] or ''
|
||||||
video.uploaded_at = datetime.fromisoformat (datum['startTime'])
|
video.uploaded_at = datetime.fromisoformat (datum['startTime'])
|
||||||
@@ -199,6 +207,7 @@ def search_nico_by_tags (
|
|||||||
'targets': 'tagsExact',
|
'targets': 'tagsExact',
|
||||||
'_sort': '-viewCounter',
|
'_sort': '-viewCounter',
|
||||||
'fields': ('contentId,'
|
'fields': ('contentId,'
|
||||||
|
'userId,'
|
||||||
'title,'
|
'title,'
|
||||||
'tags,'
|
'tags,'
|
||||||
'description,'
|
'description,'
|
||||||
@@ -220,6 +229,7 @@ def search_nico_by_tags (
|
|||||||
video_data = fetch_video_data (video.code)['data']
|
video_data = fetch_video_data (video.code)['data']
|
||||||
result_data.append ({
|
result_data.append ({
|
||||||
'contentId': video.code,
|
'contentId': video.code,
|
||||||
|
'userId': video_data['video']['userId'],
|
||||||
'title': video_data['video']['title'],
|
'title': video_data['video']['title'],
|
||||||
'tags': ' '.join (map (lambda t: t['name'],
|
'tags': ' '.join (map (lambda t: t['name'],
|
||||||
video_data['tag']['items'])),
|
video_data['tag']['items'])),
|
||||||
@@ -243,6 +253,7 @@ class VideoSearchParam (TypedDict):
|
|||||||
|
|
||||||
class VideoResult (TypedDict):
|
class VideoResult (TypedDict):
|
||||||
contentId: str
|
contentId: str
|
||||||
|
userId: int | None
|
||||||
title: str
|
title: str
|
||||||
tags: str
|
tags: str
|
||||||
description: str | None
|
description: str | None
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする