Skip to content

Commit

Permalink
[#5] fix: Videos 테이블 기본키 중복 발생 가능성 제거
Browse files Browse the repository at this point in the history
- 이전에 저장한 레코드를 모두 지우고 새로 추가하도록 변경합니다.
- maxResults 값을 30에서 50으로 변경합니다.
  • Loading branch information
YehyeokBang committed Jan 2, 2024
1 parent da134af commit e9d32a1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion youtube_video_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
params = {
"key": YOUTUBE_API_KEY,
"part": "snippet",
"maxResults": 30,
"maxResults": 50,
"q": "거북목%7C스트레칭%7C",
"type": "video",
"videoDuration" : "medium",
Expand All @@ -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()

0 comments on commit e9d32a1

Please sign in to comment.