-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
22 lines (17 loc) · 757 Bytes
/
db.py
File metadata and controls
22 lines (17 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
import os
import pymysql
import base64
import requests
import logging
def connect_RDS(host, port, username, password, database):
try:
conn = pymysql.connect(host=host, user=username, passwd=password, db=database, port=port, use_unicode=True, charset='utf8')
cursor = conn.cursor()
except:
logging.error('Failed to connect RDS')
sys.exit(1)
return conn, cursor
def insert_news(title, news_id, news_date, summary, image_url, caption, issue_rank=0, keyword="None"):
q = f"INSERT INTO news (title, news_id, news_date, summary, image_url, caption, issue_rank, keyword) VALUES ('{title}', {news_id}, '{news_date}', '{summary}', '{image_url}', '{caption}', {issue_rank}, '{keyword}');"
return q