From e9d32a138c7cc62ea35350b8eee6d2153c667ddd Mon Sep 17 00:00:00 2001 From: Yehyeok Bang Date: Tue, 2 Jan 2024 09:52:41 +0900 Subject: [PATCH] =?UTF-8?q?[#5]=20fix:=20Videos=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EA=B8=B0=EB=B3=B8=ED=82=A4=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=EA=B0=80=EB=8A=A5=EC=84=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이전에 저장한 레코드를 모두 지우고 새로 추가하도록 변경합니다. - maxResults 값을 30에서 50으로 변경합니다. --- youtube_video_crawler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/youtube_video_crawler.py b/youtube_video_crawler.py index b0a061a..d66aca8 100644 --- a/youtube_video_crawler.py +++ b/youtube_video_crawler.py @@ -20,7 +20,7 @@ params = { "key": YOUTUBE_API_KEY, "part": "snippet", - "maxResults": 30, + "maxResults": 50, "q": "거북목%7C스트레칭%7C", "type": "video", "videoDuration" : "medium", @@ -31,12 +31,18 @@ data = [(response["id"]["videoId"], response["snippet"]["title"], response["snippet"]["thumbnails"]["medium"]["url"]) for response in responses["items"]] with conn.cursor() as cursor: + delete_sql = """ + DELETE FROM videos + """ + cursor.execute(delete_sql) + sql = """ INSERT INTO videos (video_id, title, thumbnail_url) VALUES (%s, %s, %s) """ cursor.executemany(sql, data) + conn.commit() conn.close() \ No newline at end of file