Cafe24์ ์ ํ๋ธ ์ฝํ ์ธ ํต๊ณ ๋ฐ์ดํฐ๋ฅผ ๋งค์ผ ์์งํด BigQuery์ ์ ์ฌํ๋ ์๋ํ ํ์ดํ๋ผ์ธ์ ๋ง๋ค๋ฉด์ ๋ค์ํ ์ํ์ฐฉ์ค๋ฅผ ๊ฒช์๋ค. ํนํ Cloud Functions, Selenium ํฌ๋กค๋ง, CSV ์ฒ๋ฆฌ, BigQuery ์คํค๋ง ์ค๊ณ์ ๊ด๋ จํด ์์ ๋ฌธ์ ๋ค์ด ๋ง์๊ณ , ์ด๋ฅผ ํ๋์ฉ ํด๊ฒฐํด๊ฐ๋ฉฐ ์๋ํ์ ์ฑ๊ณตํ ๊ธฐ๋ก์ ๊ณต์ ํด๋ณด๋ ค ํ๋ค.
export-cafe24-contents
: ํฌ๋กค๋ง ๋ฐ ์
๋ก๋ ํจ์ํ์
.xlsx
ํ์ผ์ด Excel์์ ์ด๋ฆฌ์ง ์๊ณ ๊ฒฝ๊ณ ๋ฐ์์์ธ
.csv
ํฌ๋งท์ด์ง๋ง ํ์ฅ์๋ง .xlsx
ํด๊ฒฐ
.csv
๋ก ์ ์ฅํ์ฌ ์ฒ๋ฆฌresponse.content
๋ฅผ wb
๋ก ์ ์ฅ ํ csv.reader
๋ก ์ฌํ์ฑํ์ฌ ํด๊ฒฐํ์
ํด๊ฒฐ
cookies = driver.get_cookies()
session = requests.Session()
for cookie in cookies:
session.cookies.set(cookie["name"], cookie["value"])
โ Selenium์์ ๋ฐ์ ์ฟ ํค๋ฅผ Requests ์ธ์ ์ ์ฎ๊ธฐ๋ ๋ฐฉ์์ผ๋ก ํด๊ฒฐ
์๊ตฌ์ฌํญ
๊ธฐ์กด ์ฝ๋
start_date = "2025-02-22"
end_date = "2025-03-23"
๋ณ๊ฒฝ ์ฝ๋
target_date = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
โ ์ ์ผ ๊ธฐ์ค์ผ๋ก start/end ๋ ์ง๋ฅผ ๋์ผํ๊ฒ ์ค์ ํ์ฌ ํด๊ฒฐ
ํ์
NotFound: Table ... was not found
์๋ฌํด๊ฒฐ
get_table()
๋ก ํ์ธํ๊ณ ์์ผ๋ฉด dataset โ table ์์๋ก ์๋ ์์ฑ ๋ก์ง ์์ฑtry:
client.get_table(table_ref)
except Exception:
# dataset ์์ฑ โ table ์์ฑ
์๊ตฌ์ฌํญ
2025-01-01
๋ถํฐ ํ๋ฃจ์ฉ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ์์งํด์ ์ ์ฌํ๊ณ ์ถ์ํด๊ฒฐ
def backfill(start_date_str, end_date_str):
...
โ ๋ ์ง๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ๋๊ธธ ์ ์๊ฒ download_csv(target_date=...)
, load_to_bigquery(target_date=...)
ํจ์ ๋ชจ๋ ๋ฆฌํฉํ ๋ง
๋ฌธ์ ์
ํด๊ฒฐ
header = ["log_date", "content_name", "channel_name", "sales", "order_count", "visitor_count", "conversion_rate"]
โ CSV ์ ์ฅ ์ ์ปฌ๋ผ๋ช ์ ์๋ฌธ์ผ๋ก ๋ณ๊ฒฝํ์ฌ ํต์ผ
๋ฌธ์ ์
ํด๊ฒฐ
DELETE FROM `{table_ref}` WHERE log_date = '{target_date}'
โ ์ ์ฌ ์ ์ ํด๋น ๋ ์ง์ ๊ธฐ์กด ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํ ์๋ก insert