translate_tool_internal / test /update_all_dev_shops.py
AtoX-Keisuke-Ogawa
add request icon function, and fix upload function for all data in dev/prod-shops table
17036cc
Raw
History Blame Contribute Delete
4.85 kB
#!/usr/bin/env python
# coding: utf-8
# # sample data creation
# In[1]:
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pandas as pd
from config.logger import logger
from services.s3_manager import S3Manager
from logging import INFO, DEBUG
from decimal import Decimal
logger.setLevel(INFO)
pd.set_option('display.max_columns', None)
from services.dynamo_manager import DynamoDBManager
from datetime import datetime, timedelta, timezone
import time
from services.s3_manager import S3Manager
def get_current_time():
#現在のナノ秒単位の時刻を取得
current_time_ns = time.time_ns()
jst_time = datetime.now(timezone(timedelta(hours=9)))
epoch = datetime(1970, 1, 1, tzinfo=timezone.utc) # エポック(UTC)
jst_timedelta = jst_time - epoch # 経過時間(timedelta)
current_time_jst_ns = int(jst_timedelta.total_seconds() * 1e9)
logger.info(f"日本時間(ナノ秒単位) : {current_time_jst_ns}")
return current_time_jst_ns
def get_input_excel(shop_id):
# ユーザーからのインプットデータを読み取る
bucket_name = "operation-menu-boy"
prefix = f"{shop_id}/スプレッドシート/"
s3_manager = S3Manager(bucket_name)
# S3バケット内の指定されたプレフィックスの下にあるファイルをリストアップ
response = s3_manager.s3.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
if "Contents" not in response:
raise FileNotFoundError(f"No files found in {prefix}")
# 最新のファイルを選択
latest_file = max(response["Contents"], key=lambda x: x["LastModified"])
excel_file_name = latest_file["Key"].split("/")[-1]
file_key = latest_file["Key"]
excel = s3_manager.get_excel_from_s3(file_key)
return excel, excel_file_name
db_manager = DynamoDBManager(environment='dev')
current_time_jst_ns = get_current_time()
shop_id_list = []
sitems = db_manager.scan_all("shops")
for i in sitems:
shop_id_list.append(i['shop_id'])
for shop_id in shop_id_list:
excel, excel_file_name = get_input_excel(shop_id)
# dev-shops用のデータ抽出
shop_df = excel.parse(sheet_name="店舗")
shop_df.columns = shop_df.columns.str.replace("(", "(").str.replace(")", ")")
shops_data = {
"shop_id": shop_id,
"excel_name": excel_file_name,
"shop_name_ja": shop_df['店舗名(日本語)'][0],
"shop_name_cn_s": shop_df['店舗名(簡体字)'][0],
"shop_name_cn_t": shop_df['店舗名(繁体字)'][0],
"shop_name_en": shop_df['店舗名(英語)'][0],
"shop_name_kr": shop_df['店舗名(韓国語)'][0],
"created_at": Decimal(current_time_jst_ns),
"updated_at": Decimal(current_time_jst_ns)
}
# shops DB にデータを追加
# db_manager.delete_shop(shop_id) # 既存のデータを削除
db_manager.put_item("shops", shops_data)
sitems = db_manager.scan_all("shops")
print(f"{shops_data['shop_id']}: {len(sitems)} items found.")
# shop_id_list = [
# 'champonyoshimaru-nihonbashi-dinner',
# 'champonyoshimaru-nihonbashi-lunch',
# 'champonyoshimaru-shinagawakonan-dinner',
# # 'champonyoshimaru-sinagawakonan-lunch', # not exist
# 'dinner-heros-steakhouse-akihabara',
# 'dinner-heros-steakhouse-ikebukurosunshine',
# 'dinner-heros-steakhouse-kichijoji',
# 'dinner-heros-steakhouse-sasazuka',
# 'dinner-heros-steakhouse-yodobashiyokohama',
# # 'fkonaka-test', # not exist
# 'frijoles_sibuyadougenzaka',
# 'frijoles_tokyomidtown_yaesu',
# 'frijoles_tokyomidtown_yaesu2',
# # 'hata-bura', # not exist
# # 'hata-bura-non-dishsets-test', # not exist
# 'kotobukiya-yoyogi',
# 'lunch-heros-steakhouse-akihabara',
# 'lunch-heros-steakhouse-ikebukurosunshine',
# 'lunch-heros-steakhouse-kichijoji',
# # 'lunch-heros-steakhouse-kichijyouji', # not exist
# 'lunch-heros-steakhouse-yodobashiyokohama',
# 'ponchiken-kanda',
# 'ponchiken-kanda-lunch',
# 'shibuya-kitokito',
# 'shibuya-pikuru',
# 'tonkatsu-ziesu-shinjuku',
# 'yoshimaru-atrevieotsuka',
# 'yoshimaru-kayabachou-dinner',
# 'yoshimaru-kayabachou-lunch',
# 'yoshimaru-kudanshita-dinner',
# 'yoshimaru-kudanshita-lunch',
# 'yoshimaru-marunouchi-dinner',
# 'yoshimaru-marunouchi-lunch',
# 'yoshimaru-ningyouchou-dinner',
# 'yoshimaru-ningyouchou-lunch',
# 'yoshimaru-otemachi-dinner',
# 'yoshimaru-otemachi-lunch',
# 'yoshimaru-shibadaimon-dinner',
# 'yoshimaru-shibadaimon-lunch',
# 'yoshimaru-shinagawakonan-dinner',
# 'yoshimaru-shinagawakonan-lunch',
# 'yoshimaru-tameike-dinner',
# 'yoshimaru-tameike-lunch',
# 'yoshimaru-yaesu-dinner',
# 'yoshimaru-yaesu-lunch'
# ]