print で出力するのは無意味だったので取消し
このコミットが含まれているのは:
+43
-45
@@ -128,8 +128,6 @@ def main (
|
|||||||
api_data, now)
|
api_data, now)
|
||||||
|
|
||||||
conn.commit ()
|
conn.commit ()
|
||||||
print ('Committed.')
|
|
||||||
|
|
||||||
conn.close ()
|
conn.close ()
|
||||||
|
|
||||||
|
|
||||||
@@ -312,7 +310,7 @@ class VideoDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> VideoDto | None:
|
) -> VideoDto | None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
code,
|
code,
|
||||||
@@ -325,7 +323,7 @@ class VideoDao:
|
|||||||
WHERE
|
WHERE
|
||||||
id = %s
|
id = %s
|
||||||
ORDER BY
|
ORDER BY
|
||||||
id""", (video_id,)))
|
id""", (video_id,))
|
||||||
row = cast (VideoRow | None, c.fetchone ())
|
row = cast (VideoRow | None, c.fetchone ())
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -336,7 +334,7 @@ class VideoDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> list[VideoDto]:
|
) -> list[VideoDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
code,
|
code,
|
||||||
@@ -347,7 +345,7 @@ class VideoDao:
|
|||||||
FROM
|
FROM
|
||||||
videos
|
videos
|
||||||
ORDER BY
|
ORDER BY
|
||||||
id"""))
|
id""")
|
||||||
videos: list[VideoDto] = []
|
videos: list[VideoDto] = []
|
||||||
for row in cast (list[VideoRow], c.fetchall ()):
|
for row in cast (list[VideoRow], c.fetchall ()):
|
||||||
videos.append (self._create_dto_from_row (row, with_relation_tables))
|
videos.append (self._create_dto_from_row (row, with_relation_tables))
|
||||||
@@ -357,7 +355,7 @@ class VideoDao:
|
|||||||
self,
|
self,
|
||||||
) -> list[VideoDto]:
|
) -> list[VideoDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
code,
|
code,
|
||||||
@@ -368,7 +366,7 @@ class VideoDao:
|
|||||||
FROM
|
FROM
|
||||||
videos
|
videos
|
||||||
WHERE
|
WHERE
|
||||||
deleted_at IS NULL"""))
|
deleted_at IS NULL""")
|
||||||
videos: list[VideoDto] = []
|
videos: list[VideoDto] = []
|
||||||
for row in cast (list[VideoRow], c.fetchall ()):
|
for row in cast (list[VideoRow], c.fetchall ()):
|
||||||
videos.append (self._create_dto_from_row (row, False))
|
videos.append (self._create_dto_from_row (row, False))
|
||||||
@@ -387,7 +385,7 @@ class VideoDao:
|
|||||||
deleted_at = cast (datetime | None, deleted_at)
|
deleted_at = cast (datetime | None, deleted_at)
|
||||||
|
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
videos(
|
videos(
|
||||||
code,
|
code,
|
||||||
@@ -412,7 +410,7 @@ class VideoDao:
|
|||||||
video.title,
|
video.title,
|
||||||
video.description,
|
video.description,
|
||||||
video.uploaded_at,
|
video.uploaded_at,
|
||||||
deleted_at)))
|
deleted_at))
|
||||||
video.id_ = c.lastrowid
|
video.id_ = c.lastrowid
|
||||||
if with_relation_tables:
|
if with_relation_tables:
|
||||||
if video.video_tags is not None:
|
if video.video_tags is not None:
|
||||||
@@ -438,13 +436,13 @@ class VideoDao:
|
|||||||
if not video_ids:
|
if not video_ids:
|
||||||
return
|
return
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
UPDATE
|
UPDATE
|
||||||
videos
|
videos
|
||||||
SET
|
SET
|
||||||
deleted_at = %%s
|
deleted_at = %%s
|
||||||
WHERE
|
WHERE
|
||||||
id IN (%s)""" % ', '.join (['%s'] * len (video_ids)), (at, *video_ids)))
|
id IN (%s)""" % ', '.join (['%s'] * len (video_ids)), (at, *video_ids))
|
||||||
|
|
||||||
def _create_dto_from_row (
|
def _create_dto_from_row (
|
||||||
self,
|
self,
|
||||||
@@ -496,7 +494,7 @@ class VideoTagDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> list[VideoTagDto]:
|
) -> list[VideoTagDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
video_id,
|
video_id,
|
||||||
@@ -508,7 +506,7 @@ class VideoTagDao:
|
|||||||
WHERE
|
WHERE
|
||||||
video_id = %s
|
video_id = %s
|
||||||
ORDER BY
|
ORDER BY
|
||||||
id""", (video_id,)))
|
id""", (video_id,))
|
||||||
video_tags: list[VideoTagDto] = []
|
video_tags: list[VideoTagDto] = []
|
||||||
for row in cast (list[VideoTagRow], c.fetchall ()):
|
for row in cast (list[VideoTagRow], c.fetchall ()):
|
||||||
video_tags.append (self._create_dto_from_row (row, with_relation_tables))
|
video_tags.append (self._create_dto_from_row (row, with_relation_tables))
|
||||||
@@ -520,7 +518,7 @@ class VideoTagDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> list[VideoTagDto]:
|
) -> list[VideoTagDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
video_id,
|
video_id,
|
||||||
@@ -533,7 +531,7 @@ class VideoTagDao:
|
|||||||
video_id = %s
|
video_id = %s
|
||||||
AND (untagged_at IS NULL)
|
AND (untagged_at IS NULL)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
id""", (video_id,)))
|
id""", (video_id,))
|
||||||
video_tags: list[VideoTagDto] = []
|
video_tags: list[VideoTagDto] = []
|
||||||
for row in cast (list[VideoTagRow], c.fetchall ()):
|
for row in cast (list[VideoTagRow], c.fetchall ()):
|
||||||
video_tags.append (self._create_dto_from_row (row, with_relation_tables))
|
video_tags.append (self._create_dto_from_row (row, with_relation_tables))
|
||||||
@@ -546,7 +544,7 @@ class VideoTagDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> VideoTagDto | None:
|
) -> VideoTagDto | None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
video_id,
|
video_id,
|
||||||
@@ -557,7 +555,7 @@ class VideoTagDao:
|
|||||||
video_tags
|
video_tags
|
||||||
WHERE
|
WHERE
|
||||||
video_id = %s
|
video_id = %s
|
||||||
AND tag_id = %s""", (video_id, tag_id)))
|
AND tag_id = %s""", (video_id, tag_id))
|
||||||
row = cast (VideoTagRow, c.fetchone ())
|
row = cast (VideoTagRow, c.fetchone ())
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -576,7 +574,7 @@ class VideoTagDao:
|
|||||||
untagged_at = cast (date | None, untagged_at)
|
untagged_at = cast (date | None, untagged_at)
|
||||||
|
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
video_tags(
|
video_tags(
|
||||||
video_id,
|
video_id,
|
||||||
@@ -589,7 +587,7 @@ class VideoTagDao:
|
|||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s)""", (video_tag.video_id, video_tag.tag_id,
|
%s)""", (video_tag.video_id, video_tag.tag_id,
|
||||||
video_tag.tagged_at, untagged_at)))
|
video_tag.tagged_at, untagged_at))
|
||||||
video_tag.id_ = c.lastrowid
|
video_tag.id_ = c.lastrowid
|
||||||
if with_relation_tables:
|
if with_relation_tables:
|
||||||
if video_tag.video is not None:
|
if video_tag.video is not None:
|
||||||
@@ -610,7 +608,7 @@ class VideoTagDao:
|
|||||||
untagged_at = cast (date | None, untagged_at)
|
untagged_at = cast (date | None, untagged_at)
|
||||||
|
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
video_tags(
|
video_tags(
|
||||||
video_id,
|
video_id,
|
||||||
@@ -631,7 +629,7 @@ class VideoTagDao:
|
|||||||
untagged_at = VALUES(untagged_at)""", (video_tag.video_id,
|
untagged_at = VALUES(untagged_at)""", (video_tag.video_id,
|
||||||
video_tag.tag_id,
|
video_tag.tag_id,
|
||||||
video_tag.tagged_at,
|
video_tag.tagged_at,
|
||||||
untagged_at)))
|
untagged_at))
|
||||||
video_tag.id_ = c.lastrowid
|
video_tag.id_ = c.lastrowid
|
||||||
if with_relation_tables:
|
if with_relation_tables:
|
||||||
if video_tag.video is not None:
|
if video_tag.video is not None:
|
||||||
@@ -656,7 +654,7 @@ class VideoTagDao:
|
|||||||
if not tag_ids:
|
if not tag_ids:
|
||||||
return
|
return
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
UPDATE
|
UPDATE
|
||||||
video_tags
|
video_tags
|
||||||
SET
|
SET
|
||||||
@@ -704,14 +702,14 @@ class TagDao:
|
|||||||
tag_id: int,
|
tag_id: int,
|
||||||
) -> TagDto | None:
|
) -> TagDto | None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
FROM
|
FROM
|
||||||
tags
|
tags
|
||||||
WHERE
|
WHERE
|
||||||
id = %s""", (tag_id,)))
|
id = %s""", (tag_id,))
|
||||||
row = cast (TagRow | None, c.fetchone ())
|
row = cast (TagRow | None, c.fetchone ())
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -722,14 +720,14 @@ class TagDao:
|
|||||||
tag_name: str,
|
tag_name: str,
|
||||||
) -> TagDto | None:
|
) -> TagDto | None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
FROM
|
FROM
|
||||||
tags
|
tags
|
||||||
WHERE
|
WHERE
|
||||||
name = %s""", (tag_name,)))
|
name = %s""", (tag_name,))
|
||||||
row = cast (TagRow | None, c.fetchone ())
|
row = cast (TagRow | None, c.fetchone ())
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -740,11 +738,11 @@ class TagDao:
|
|||||||
tag: TagDto,
|
tag: TagDto,
|
||||||
) -> None:
|
) -> None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tags(name)
|
tags(name)
|
||||||
VALUES
|
VALUES
|
||||||
(%s)""", (tag.name,)))
|
(%s)""", (tag.name,))
|
||||||
tag.id_ = c.lastrowid
|
tag.id_ = c.lastrowid
|
||||||
|
|
||||||
def upsert (
|
def upsert (
|
||||||
@@ -752,14 +750,14 @@ class TagDao:
|
|||||||
tag: TagDto,
|
tag: TagDto,
|
||||||
) -> None:
|
) -> None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tags(name)
|
tags(name)
|
||||||
VALUES
|
VALUES
|
||||||
(%s)
|
(%s)
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
id = LAST_INSERT_ID(id),
|
id = LAST_INSERT_ID(id),
|
||||||
name = VALUES(name)""", (tag.name,)))
|
name = VALUES(name)""", (tag.name,))
|
||||||
tag.id_ = c.lastrowid
|
tag.id_ = c.lastrowid
|
||||||
|
|
||||||
def _create_dto_from_row (
|
def _create_dto_from_row (
|
||||||
@@ -789,7 +787,7 @@ class VideoHistoryDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> list[VideoHistoryDto]:
|
) -> list[VideoHistoryDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
video_id,
|
video_id,
|
||||||
@@ -798,7 +796,7 @@ class VideoHistoryDao:
|
|||||||
FROM
|
FROM
|
||||||
video_histories
|
video_histories
|
||||||
WHERE
|
WHERE
|
||||||
video_id = %s""", (video_id,)))
|
video_id = %s""", (video_id,))
|
||||||
video_histories: list[VideoHistoryDto] = []
|
video_histories: list[VideoHistoryDto] = []
|
||||||
for row in cast (list[VideoHistoryRow], c.fetchall ()):
|
for row in cast (list[VideoHistoryRow], c.fetchall ()):
|
||||||
video_histories.append (self._create_dto_from_row (row, with_relation_tables))
|
video_histories.append (self._create_dto_from_row (row, with_relation_tables))
|
||||||
@@ -809,7 +807,7 @@ class VideoHistoryDao:
|
|||||||
video_history: VideoHistoryDto,
|
video_history: VideoHistoryDto,
|
||||||
) -> None:
|
) -> None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
video_histories(
|
video_histories(
|
||||||
video_id,
|
video_id,
|
||||||
@@ -821,14 +819,14 @@ class VideoHistoryDao:
|
|||||||
%s,
|
%s,
|
||||||
%s)""", (video_history.video_id,
|
%s)""", (video_history.video_id,
|
||||||
video_history.fetched_at,
|
video_history.fetched_at,
|
||||||
video_history.views_count)))
|
video_history.views_count))
|
||||||
|
|
||||||
def upsert (
|
def upsert (
|
||||||
self,
|
self,
|
||||||
video_history: VideoHistoryDto,
|
video_history: VideoHistoryDto,
|
||||||
) -> None:
|
) -> None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
video_histories(
|
video_histories(
|
||||||
video_id,
|
video_id,
|
||||||
@@ -845,7 +843,7 @@ class VideoHistoryDao:
|
|||||||
fetched_at = VALUES(fetched_at),
|
fetched_at = VALUES(fetched_at),
|
||||||
views_count = VALUES(views_count)""", (video_history.video_id,
|
views_count = VALUES(views_count)""", (video_history.video_id,
|
||||||
video_history.fetched_at,
|
video_history.fetched_at,
|
||||||
video_history.views_count)))
|
video_history.views_count))
|
||||||
|
|
||||||
def upsert_all (
|
def upsert_all (
|
||||||
self,
|
self,
|
||||||
@@ -890,7 +888,7 @@ class CommentDao:
|
|||||||
with_relation_tables: bool,
|
with_relation_tables: bool,
|
||||||
) -> list[CommentDto]:
|
) -> list[CommentDto]:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
video_id,
|
video_id,
|
||||||
@@ -903,7 +901,7 @@ class CommentDao:
|
|||||||
FROM
|
FROM
|
||||||
comments
|
comments
|
||||||
WHERE
|
WHERE
|
||||||
video_id = %s""", (video_id,)))
|
video_id = %s""", (video_id,))
|
||||||
comments: list[CommentDto] = []
|
comments: list[CommentDto] = []
|
||||||
for row in cast (list[CommentRow], c.fetchall ()):
|
for row in cast (list[CommentRow], c.fetchall ()):
|
||||||
comments.append (self._create_dto_from_row (row, with_relation_tables))
|
comments.append (self._create_dto_from_row (row, with_relation_tables))
|
||||||
@@ -922,7 +920,7 @@ class CommentDao:
|
|||||||
vpos_ms = cast (int | None, vpos_ms)
|
vpos_ms = cast (int | None, vpos_ms)
|
||||||
|
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
comments(
|
comments(
|
||||||
video_id,
|
video_id,
|
||||||
@@ -955,7 +953,7 @@ class CommentDao:
|
|||||||
comment.content,
|
comment.content,
|
||||||
comment.posted_at,
|
comment.posted_at,
|
||||||
comment.nico_count,
|
comment.nico_count,
|
||||||
vpos_ms)))
|
vpos_ms))
|
||||||
|
|
||||||
def upsert_all (
|
def upsert_all (
|
||||||
self,
|
self,
|
||||||
@@ -1009,14 +1007,14 @@ class UserDao:
|
|||||||
user_code: str
|
user_code: str
|
||||||
) -> UserDto | None:
|
) -> UserDto | None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
code
|
code
|
||||||
FROM
|
FROM
|
||||||
users
|
users
|
||||||
WHERE
|
WHERE
|
||||||
code = %s""", (user_code,)))
|
code = %s""", (user_code,))
|
||||||
row = cast (UserRow | None, c.fetchone ())
|
row = cast (UserRow | None, c.fetchone ())
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -1027,11 +1025,11 @@ class UserDao:
|
|||||||
user: UserDto,
|
user: UserDto,
|
||||||
) -> None:
|
) -> None:
|
||||||
with self.conn.cursor (dictionary = True) as c:
|
with self.conn.cursor (dictionary = True) as c:
|
||||||
print (c.execute ("""
|
c.execute ("""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
users(code)
|
users(code)
|
||||||
VALUES
|
VALUES
|
||||||
(%s)""", (user.code,)))
|
(%s)""", (user.code,))
|
||||||
user.id_ = c.lastrowid
|
user.id_ = c.lastrowid
|
||||||
|
|
||||||
def _create_dto_from_row (
|
def _create_dto_from_row (
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする