Melon-Shake / API

2 stars 1 forks source link

[ 파이썬 ][ 데이터 삽입 및 조회 시 거쳐야 하는 필수 함수! ] #36

Closed Lucete28 closed 1 year ago

Lucete28 commented 1 year ago

Issue: :white_check_mark: 중복성 체크!


Description

is_duplicated_data(artist, album, track)

To-do

ETC

추가적인 요청은 댓 달아주세요

CODE

import psycopg2

def is_duplicated_data(artist,album,track):
  # 데이터베이스 연결 정보
  dbname = "postgres"
  user = "postgres"
  password = "12345678"
  host = "database-1.coea55uwjt5p.ap-northeast-1.rds.amazonaws.com"
  port = "5432"

  # 데이터베이스 연결
  conn = psycopg2.connect(
      dbname=dbname,
      user=user,
      password=password,
      host=host,
      port=port
  )

  # 커서 생성
  cursor = conn.cursor()
  query = f"""SELECT *
  FROM route
  WHERE artist_name = '{artist}'
    AND album_name = '{album}'
    AND track_name = '{track}';
  """python
  cursor.execute(query)
  result = cursor.fetchall()
  # 커밋
  conn.commit()

  # 연결 종료
  conn.close()
  if result:
    return True
  else:
    return False
bksooon commented 1 year ago

LGTM