컨테이너에 스프링부트 앱과 같이 동작하기
현재 수행되는 것은 mysql 5.7 버전
수정 -> mysql:8.0.29

이때 한글 설정
command:
    - --character-set-server=utf8mb4
    - --collation-server=utf8mb4_unicode_ci

테이블에 한글 추가시 에러 발생
alter table board convert to charset utf8;
-> 한글이 잘 저장됨.

Posted by 세상을 살아가는 사람
,
import pymysql
import requests
from bs4 import BeautifulSoup
import schedule

dbURL = "127.0.0.1"
dbPort = 3306
dbUser = 'study'
dbPass = 'study'

conn = pymysql.connect(
    host=dbURL, port=dbPort, user=dbUser, passwd=dbPass, db='jspdb',
    charset='utf8', use_unicode=True
)

insert_weather = "insert into jspdb.weather (city,tmef,wf,tmn,tmx) values (%s, %s, %s, %s, %s)"
select_last_date = "select tmef from jspdb.weather order by tmef desc limit 1"

def job():
    req = requests.get("http://www.weather.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108")
    html = req.text
    soup = BeautifulSoup(html, 'lxml')
    
    cur = conn.cursor()
    cur.execute(select_last_date)
    last_date = cur.fetchone()
    conn.commit()

    weather = {}
    # city, tmef, wf, tmn, tmx
    for i in soup.find_all('location'):
        weather[i.find('city').text] = []
        for j in i.find_all('data'):
            temp = []
            if(j.find('tmef').text > last_date):
                temp.append(j.find('tmef').text)
                temp.append(j.find('wf').text)
                temp.append(j.find('tmn').text)
                temp.append(j.find('tmx').text)
                weather[i.find('city').string].append(temp)
    
    for i in weather:
        for j in weather[i]:
            cur = conn.cursor()
            cur.execute(insert_weather,(i,j[0],j[1],j[2],j[3]))
            conn.commit()

schedule.every().day.at("06:00").do(job)

while True:
    schedule.run_pending()
Posted by 세상을 살아가는 사람
,
Posted by 세상을 살아가는 사람
,