init
This commit is contained in:
commit
922fa0e77a
62 changed files with 2586 additions and 0 deletions
5
functions/append-log-to-sheet/.env_debug
Executable file
5
functions/append-log-to-sheet/.env_debug
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH=projects/32472615575/secrets/sa-access-google-drive-key
|
||||
LOG_FOLDER_ID=1IZToaM9K9OJXrgV05aLO5k2ZCXpdlJzX
|
||||
MEETING_FOLDER_ID=1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw
|
||||
HUBSPOT_COMPANY_URL=https://app-na2.hubspot.com/contacts/242960467/record/0-2
|
||||
MODE=dev
|
||||
5
functions/append-log-to-sheet/.env_dev
Executable file
5
functions/append-log-to-sheet/.env_dev
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH: projects/32472615575/secrets/sa-access-google-drive-key
|
||||
LOG_FOLDER_ID: 1IZToaM9K9OJXrgV05aLO5k2ZCXpdlJzX
|
||||
MEETING_FOLDER_ID: 1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw
|
||||
HUBSPOT_COMPANY_URL: https://app-na2.hubspot.com/contacts/242960467/record/0-2
|
||||
MODE: dev
|
||||
5
functions/append-log-to-sheet/.env_prod
Executable file
5
functions/append-log-to-sheet/.env_prod
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH: projects/570987459910/secrets/sa-create-minutes-key
|
||||
LOG_FOLDER_ID: 1arL6AxpvA7N6Umg4wdrdAcRWBdKc-Jfb
|
||||
MEETING_FOLDER_ID: 0AGT_1dSq66qYUk9PVA
|
||||
HUBSPOT_COMPANY_URL: https://app.hubspot.com/contacts/22400567/record/0-2
|
||||
MODE: production
|
||||
33
functions/append-log-to-sheet/_scripts/deploy_dev.sh
Executable file
33
functions/append-log-to-sheet/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-append-log-to-sheet"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
267
functions/append-log-to-sheet/source/main.py
Executable file
267
functions/append-log-to-sheet/source/main.py
Executable file
|
|
@ -0,0 +1,267 @@
|
|||
import functions_framework
|
||||
from google.cloud import secretmanager
|
||||
from google.oauth2 import service_account
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
|
||||
SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]
|
||||
HEADER_VALUES = ["タイムスタンプ","商談日", "タイトル", "登録先企業","担当者", "ミーティングURL", "議事録URL", "HubSpot会社概要URL"]
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
# POSTリクエストの処理
|
||||
if request.method != 'POST':
|
||||
return ('', 405, {'Allow': 'POST', 'Content-Type': 'application/json'}) # メソッドがPOSTでない場合は405エラーを返す
|
||||
|
||||
"""Shows basic usage of the Drive Activity API.
|
||||
|
||||
Prints information about the last 10 events that occured the user's Drive.
|
||||
"""
|
||||
try:
|
||||
request_json = request.get_json()
|
||||
print(request_json)
|
||||
title = request_json['title'] # 会議タイトル
|
||||
document_id = request_json['document_id'] # 議事録ファイルのID
|
||||
matched_company_id = request_json['matched_company_id'] # マッチした会社ID
|
||||
matched_company_name = request_json['matched_company_name'] # マッチした会社名
|
||||
host_name = request_json['host_name'] # ホストユーザー名
|
||||
video_url = request_json['video_url'] # 会議履歴URL
|
||||
starts_at = request_json['starts_at'] # 開始日時
|
||||
|
||||
log_folder_id = os.getenv("LOG_FOLDER_ID") # 共有ドライブID
|
||||
meeting_folder_id = os.getenv("MEETING_FOLDER_ID") # ミーティングフォルダID
|
||||
hubspot_company_url = os.getenv("HUBSPOT_COMPANY_URL") # HubSpotの会社情報URL
|
||||
mode = os.getenv("MODE") # モード(devまたはprod)
|
||||
|
||||
service_account_info = get_service_account_info()
|
||||
# 認証
|
||||
credentials = get_credentials(service_account_info)
|
||||
|
||||
# APIクライアントの構築
|
||||
drive_service = build("drive", "v3", credentials=credentials)
|
||||
sheet_service = build("sheets", "v4", credentials=credentials)
|
||||
|
||||
|
||||
# 現在日時をJSTに変換
|
||||
jst_now = datetime.now(timezone.utc).astimezone(timezone(timedelta(hours=9)))
|
||||
# JSTの現在日時を文字列に変換
|
||||
ym_str = jst_now.strftime("%Y%m")
|
||||
y_str = jst_now.strftime("%Y")
|
||||
|
||||
|
||||
# 年別のフォルダを検索
|
||||
target_folder = get_directory_files_dev(drive_service, log_folder_id, y_str) if mode == "dev" else get_directory_files_prod(drive_service, meeting_folder_id, log_folder_id, y_str)
|
||||
print("target_folder", target_folder)
|
||||
|
||||
year_folder_id = None
|
||||
if not target_folder:
|
||||
# フォルダが存在しない場合は新規作成
|
||||
year_folder_id = create_new_folder(drive_service, log_folder_id, y_str)
|
||||
else:
|
||||
# フォルダが存在する場合はそのIDを使用
|
||||
year_folder_id = target_folder[0]['id']
|
||||
print("年別のフォルダID:", year_folder_id)
|
||||
|
||||
# スプレッドシートを検索
|
||||
target_files = get_directory_files_dev(drive_service, year_folder_id, ym_str) if mode == "dev" else get_directory_files_prod(drive_service, meeting_folder_id, year_folder_id, ym_str)
|
||||
print("スプレッドシート", target_files)
|
||||
|
||||
if not target_files:
|
||||
print('not found')
|
||||
|
||||
# スプレッドシートを作成
|
||||
spreadsheet_id = create_new_spreadsheet(drive_service, year_folder_id, ym_str)
|
||||
print("スプレッドシートID:", spreadsheet_id)
|
||||
# 注意事項追加
|
||||
append_log_to_sheet(sheet_service, spreadsheet_id, ["※シート名変更厳禁"])
|
||||
# ヘッダーを追加
|
||||
append_log_to_sheet(sheet_service, spreadsheet_id, HEADER_VALUES)
|
||||
|
||||
else:
|
||||
print('found')
|
||||
# ファイルIDを取得
|
||||
spreadsheet_id = target_files[0]['id']
|
||||
|
||||
documnet_url = f"https://docs.google.com/document/d/{document_id}/edit" if document_id else ""
|
||||
hubspot_url = f"{hubspot_company_url}/{matched_company_id}" if matched_company_id else ""
|
||||
# テストログを追加
|
||||
row_data = [jst_now.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
convert_to_jst_ymd(starts_at),
|
||||
title,
|
||||
matched_company_name,
|
||||
host_name,
|
||||
video_url,
|
||||
documnet_url,
|
||||
hubspot_url
|
||||
]
|
||||
append_log_to_sheet(sheet_service, spreadsheet_id, row_data)
|
||||
print("ログを追加しました:", row_data)
|
||||
|
||||
return (json.dumps({"status": "success"}, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
|
||||
except HttpError as error:
|
||||
# TODO(developer) - Handleerrors from drive activity API.
|
||||
print(f"An error occurred: {error}")
|
||||
|
||||
|
||||
#
|
||||
# SecretManagerから秘密鍵を取得
|
||||
#
|
||||
def get_service_account_info():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# 秘密鍵取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# 秘密鍵の値をデコード
|
||||
secret_key = response.payload.data.decode("UTF-8")
|
||||
return json.loads(secret_key)
|
||||
|
||||
# Google Drive認証
|
||||
def get_credentials(service_account_info):
|
||||
credentials = service_account.Credentials.from_service_account_info(
|
||||
service_account_info,
|
||||
scopes=SCOPES
|
||||
)
|
||||
return credentials
|
||||
|
||||
|
||||
# 開発用マイドライブからのファイルを取得
|
||||
def get_directory_files_dev(service,shared_folder_id, filename):
|
||||
"""
|
||||
対象のディレクトリ配下からファイル名で検索した結果を配列で返す
|
||||
:param filename: ファイル名
|
||||
:param directory_id: ディレクトリID
|
||||
:param pages_max: 最大ページ探索数
|
||||
:return: ファイルリスト
|
||||
"""
|
||||
items = []
|
||||
page = 0
|
||||
pages_max = 10 # 最大ページ数
|
||||
while True:
|
||||
page += 1
|
||||
if page == pages_max:
|
||||
break
|
||||
results = service.files().list(
|
||||
corpora="user",
|
||||
includeItemsFromAllDrives=True,
|
||||
includeTeamDriveItems=True,
|
||||
q=f"'{shared_folder_id}' in parents and name = '{filename}' and trashed = false",
|
||||
supportsAllDrives=True,
|
||||
pageSize=10,
|
||||
fields="nextPageToken, files(id, name)").execute()
|
||||
items += results.get("files", [])
|
||||
|
||||
page_token = results.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
return items
|
||||
|
||||
# 本番用共有ドライブからのファイルを取得
|
||||
def get_directory_files_prod(service,shared_folder_id,sub_folder_id,filename):
|
||||
"""
|
||||
対象のディレクトリ配下からファイル名で検索した結果を配列で返す
|
||||
:param filename: ファイル名
|
||||
:param directory_id: ディレクトリID
|
||||
:param pages_max: 最大ページ探索数
|
||||
:return: ファイルリスト
|
||||
"""
|
||||
items = []
|
||||
page = 0
|
||||
pages_max = 10 # 最大ページ数
|
||||
while True:
|
||||
page += 1
|
||||
if page == pages_max:
|
||||
break
|
||||
results = service.files().list(
|
||||
corpora="drive",
|
||||
driveId=shared_folder_id,
|
||||
includeItemsFromAllDrives=True,
|
||||
includeTeamDriveItems=True,
|
||||
q=f"'{sub_folder_id}' in parents and name = '{filename}' and trashed = false",
|
||||
supportsAllDrives=True,
|
||||
pageSize=10,
|
||||
fields="nextPageToken, files(id, name, parents)").execute()
|
||||
items += results.get("files", [])
|
||||
|
||||
page_token = results.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
return items
|
||||
|
||||
def create_new_folder(service, sub_folder_id, title):
|
||||
"""
|
||||
Google Drive APIを使用して新しいフォルダを作成する
|
||||
:param service: Google Drive APIのサービスオブジェクト
|
||||
:param title: フォルダのタイトル
|
||||
:return: 作成したフォルダのID
|
||||
"""
|
||||
file_metadata = {
|
||||
"name": title,
|
||||
"parents": [sub_folder_id], # 共有ドライブのIDを指定
|
||||
"mimeType": "application/vnd.google-apps.folder",
|
||||
}
|
||||
|
||||
result = service.files().create(body=file_metadata, fields="id", supportsAllDrives=True).execute()
|
||||
return result.get('id')
|
||||
|
||||
|
||||
def create_new_spreadsheet(service,folder_id,title):
|
||||
"""
|
||||
Google Sheets APIを使用して新しいスプレッドシートを作成する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param title: スプレッドシートのタイトル
|
||||
:return: 作成したスプレッドシートのID
|
||||
"""
|
||||
file_metadata = {
|
||||
'name': title,
|
||||
'parents': [folder_id], # 作成したフォルダのIDを指定
|
||||
'mimeType': 'application/vnd.google-apps.spreadsheet',
|
||||
}
|
||||
result = (
|
||||
service.files()
|
||||
.create(body=file_metadata, fields="id", supportsAllDrives=True)
|
||||
.execute()
|
||||
)
|
||||
return result.get("id")
|
||||
|
||||
|
||||
def append_log_to_sheet(service, spreadsheet_id, row_data):
|
||||
"""
|
||||
Google Sheets APIを使用してスプレッドシートにログを追加する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param spreadsheet_id: スプレッドシートのID
|
||||
:param row_data: 追加するログデータ(リスト形式)
|
||||
"""
|
||||
body = {
|
||||
'values': [row_data]
|
||||
}
|
||||
|
||||
# スプレッドシートにログを追加
|
||||
result = service.spreadsheets().values().append(
|
||||
spreadsheetId=spreadsheet_id,
|
||||
range='Sheet1',
|
||||
valueInputOption="USER_ENTERED",
|
||||
insertDataOption='INSERT_ROWS',
|
||||
body=body,
|
||||
).execute()
|
||||
print(f"{result.get('updates').get('updatedCells')} cells appended.")
|
||||
|
||||
|
||||
|
||||
|
||||
def convert_to_jst_ymd(starts_at):
|
||||
"""
|
||||
開始日時をYYYY年MM月DD日形式に変換する
|
||||
:param starts_at: 開始日時の文字列
|
||||
:return: YYYY年MM月DD日形式の文字列
|
||||
"""
|
||||
# 開始日時をUTCからJSTに変換
|
||||
dt = datetime.fromisoformat(starts_at.replace("Z", "+00:00")).astimezone(timezone(timedelta(hours=9)))
|
||||
# YYYY年MM月DD日形式に変換
|
||||
return dt.strftime("%Y年%m月%d日")
|
||||
5
functions/append-log-to-sheet/source/requirements.txt
Executable file
5
functions/append-log-to-sheet/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
google-cloud-secret-manager
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
5
functions/create-hubspot-meeting-log/.env_debug
Executable file
5
functions/create-hubspot-meeting-log/.env_debug
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID=datacom-poc
|
||||
LOCATION=asia-northeast1
|
||||
BUCKET=meeting-report-data
|
||||
KEY_PATH=projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
MODE=dev
|
||||
5
functions/create-hubspot-meeting-log/.env_dev
Executable file
5
functions/create-hubspot-meeting-log/.env_dev
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: datacom-poc
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-report-data
|
||||
KEY_PATH: projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
MODE: dev
|
||||
5
functions/create-hubspot-meeting-log/.env_prod
Executable file
5
functions/create-hubspot-meeting-log/.env_prod
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: rational-timing-443808-u0
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-data
|
||||
KEY_PATH: projects/570987459910/secrets/mrt-hubspot-accesstoken
|
||||
MODE: prod
|
||||
33
functions/create-hubspot-meeting-log/_scripts/deploy_dev.sh
Executable file
33
functions/create-hubspot-meeting-log/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-create-hubspot-meeting-log"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
200
functions/create-hubspot-meeting-log/source/main.py
Executable file
200
functions/create-hubspot-meeting-log/source/main.py
Executable file
|
|
@ -0,0 +1,200 @@
|
|||
import functions_framework
|
||||
from google.cloud import storage, secretmanager
|
||||
import os
|
||||
import hubspot
|
||||
from hubspot.crm.objects.meetings import SimplePublicObjectInputForCreate, ApiException
|
||||
import requests
|
||||
import csv
|
||||
import io
|
||||
import re
|
||||
import jaconv
|
||||
from rapidfuzz import process, fuzz
|
||||
import json
|
||||
|
||||
CUTOFF = 80 # Fuzzy 閾値 (0-100)
|
||||
LEGAL_SUFFIX = r'(株式会社|(株)|\(株\)|有限会社|合同会社|Inc\.?|Corp\.?|Co\.?Ltd\.?)'
|
||||
|
||||
cs_client = storage.Client(project=os.getenv("PROJECT_ID"))
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
try:
|
||||
request_json = request.get_json()
|
||||
print(request_json)
|
||||
|
||||
mode = os.getenv("MODE") # モード(devまたはprod)
|
||||
title = request_json['title']
|
||||
host_id = request_json['host_id'] if mode == 'prod' else 'ksuenaga@datacom.jp' # ホストユーザーID(開発環境では固定値を使用)
|
||||
starts_at = request_json['starts_at']
|
||||
ends_at = request_json['ends_at']
|
||||
minutes = request_json['minutes']
|
||||
|
||||
# タイトルから【】を削除
|
||||
title = title.replace("【", "").replace("】", "")
|
||||
# タイトルから企業名を抽出
|
||||
company_name = title.split("様")[0].strip() # "様" で分割して企業名を取得
|
||||
print("抽出した企業名:", company_name)
|
||||
|
||||
# 会社名から会社IDを取得
|
||||
matched_company_id, matched_company_name = search_company(company_name)
|
||||
|
||||
# マッチしたときだけ処理を行う
|
||||
if matched_company_id:
|
||||
# ユーザーIDを取得
|
||||
by_email = load_owners()
|
||||
user_id = None
|
||||
if host_id in by_email:
|
||||
user_id = by_email[host_id]['id']
|
||||
print("取得したユーザーID:", user_id)
|
||||
|
||||
# 改行コードを <br> タグに変換
|
||||
minutes_html = minutes.replace("\n", "<br>")
|
||||
# ミーティングログを作成
|
||||
create_meeting_log(matched_company_id, title, user_id, starts_at, ends_at, minutes_html)
|
||||
|
||||
|
||||
response_data = {
|
||||
"matched_company_id": matched_company_id, # マッチした会社ID
|
||||
"matched_company_name": matched_company_name, # マッチした会社名
|
||||
}
|
||||
return (json.dumps(response_data, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
except ApiException as e:
|
||||
print("Exception when calling basic_api->create: %s\n" % e)
|
||||
|
||||
|
||||
def normalize(name: str) -> str:
|
||||
"""表記ゆれ吸収用の正規化"""
|
||||
n = jaconv.z2h(name, kana=False, digit=True, ascii=True).lower()
|
||||
n = re.sub(LEGAL_SUFFIX, '', n)
|
||||
return re.sub(r'[\s\-・・,,、\.]', '', n)
|
||||
|
||||
|
||||
# GCSから会社一覧取得
|
||||
def load_componies():
|
||||
"""
|
||||
毎回 Cloud Storage から CSV を読み込む。
|
||||
*応答速度を気にしない* 前提なのでキャッシュしなくても OK。
|
||||
"""
|
||||
|
||||
blob = cs_client.bucket(os.getenv("BUCKET")).blob('master/mst_company.csv')
|
||||
raw = blob.download_as_bytes() # bytes
|
||||
|
||||
recs, by_norm = [], {}
|
||||
with io.StringIO(raw.decode("utf-8")) as f:
|
||||
reader = csv.DictReader(f)
|
||||
for row in reader:
|
||||
row["norm_name"] = normalize(row["company_name"])
|
||||
recs.append(row)
|
||||
by_norm[row["norm_name"]] = row # 完全一致用ハッシュ
|
||||
|
||||
return recs, by_norm # (list[dict], dict)
|
||||
|
||||
|
||||
# GCSから担当者一覧取得
|
||||
def load_owners():
|
||||
"""
|
||||
GCS から担当者一覧 CSV を読み込み、
|
||||
email -> row 辞書 のマッピングを返す
|
||||
"""
|
||||
|
||||
blob = cs_client.bucket(os.getenv("BUCKET")).blob('master/mst_owner.csv')
|
||||
raw = blob.download_as_bytes() # bytes
|
||||
|
||||
by_email = {}
|
||||
with io.StringIO(raw.decode("utf-8")) as f:
|
||||
reader = csv.DictReader(f)
|
||||
for row in reader:
|
||||
# row に "email" と "user_id" フィールドがある前提
|
||||
email = row["email"].strip().lower()
|
||||
by_email[email] = row
|
||||
|
||||
return by_email
|
||||
|
||||
|
||||
|
||||
def fuzzy_candidates(norm: str, recs):
|
||||
"""
|
||||
norm : 正規化済み検索語
|
||||
recs : 会社レコード list[dict] (norm_name 含む)
|
||||
戻り値 : list[(score:int, idx:int)]
|
||||
"""
|
||||
top = 2 # 上位 2 件を取得
|
||||
matches = process.extract(
|
||||
norm,
|
||||
[r["norm_name"] for r in recs],
|
||||
scorer=fuzz.WRatio,
|
||||
score_cutoff=CUTOFF,
|
||||
limit=top
|
||||
)
|
||||
print("ファジーマッチ結果:", matches)
|
||||
if len(matches) == 0:
|
||||
return None # マッチなしの場合は None を返す
|
||||
elif len(matches) == 1:
|
||||
return recs[matches[0][2]] # 上位 1 件のみの場合はそのレコードを返す
|
||||
else:
|
||||
if(matches[0][1] == matches[1][1]):
|
||||
return None # 上位 2 件のスコアが同じ場合は None を返す
|
||||
return recs[matches[0][2]] # 上位 1 件のみの場合はそのレコードを返す
|
||||
|
||||
|
||||
def search_company(company_name):
|
||||
# -------------------- マスタ読み込み --------------------
|
||||
recs, by_norm = load_componies()
|
||||
norm_company_name = normalize(company_name)
|
||||
print("正規化した企業名:", norm_company_name)
|
||||
|
||||
matched_company_id = None
|
||||
matched_company_name = None
|
||||
# -------------------- 完全一致 --------------------
|
||||
if norm_company_name in by_norm:
|
||||
matched_company_id = by_norm[norm_company_name]["company_id"]
|
||||
matched_company_name = by_norm[norm_company_name]["company_name"]
|
||||
|
||||
# -------------------- ファジーマッチ複数 --------------------
|
||||
else :
|
||||
result = fuzzy_candidates(norm_company_name, recs)
|
||||
if result:
|
||||
matched_company_id = result["company_id"]
|
||||
matched_company_name = result["company_name"]
|
||||
|
||||
print("マッチした会社ID:", matched_company_id)
|
||||
print("マッチした会社名:", matched_company_name)
|
||||
return matched_company_id, matched_company_name
|
||||
|
||||
|
||||
def create_meeting_log(company_id ,title, user_id, starts_at, ends_at, minutes):
|
||||
"""
|
||||
HubSpot API を使ってミーティングログを作成する。
|
||||
"""
|
||||
access_key = get_access_key() # Secret Manager からアクセストークンを取得
|
||||
hs_client = hubspot.Client.create(access_token=access_key)
|
||||
|
||||
properties = {
|
||||
"hs_timestamp": starts_at,
|
||||
"hs_meeting_title": title,
|
||||
"hubspot_owner_id": user_id,
|
||||
"hs_meeting_body": minutes,
|
||||
"hs_meeting_start_time": starts_at,
|
||||
"hs_meeting_end_time": ends_at,
|
||||
|
||||
}
|
||||
|
||||
simple_public_object_input_for_create = SimplePublicObjectInputForCreate(
|
||||
associations=[{"types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":188}],"to":{"id":company_id}}],
|
||||
properties=properties
|
||||
)
|
||||
|
||||
api_response = hs_client.crm.objects.meetings.basic_api.create(simple_public_object_input_for_create=simple_public_object_input_for_create)
|
||||
print(api_response)
|
||||
|
||||
#
|
||||
# SecretManagerからアクセストークンを取得
|
||||
#
|
||||
def get_access_key():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# アクセストークン取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# アクセストークンをデコード
|
||||
access_token = response.payload.data.decode("UTF-8")
|
||||
return access_token
|
||||
8
functions/create-hubspot-meeting-log/source/requirements.txt
Executable file
8
functions/create-hubspot-meeting-log/source/requirements.txt
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
functions-framework==3.*
|
||||
Flask
|
||||
google-cloud-storage
|
||||
google-cloud-workflows
|
||||
google-cloud-secret-manager
|
||||
hubspot-api-client
|
||||
rapidfuzz
|
||||
jaconv
|
||||
5
functions/create-log-sheet/.env_debug
Executable file
5
functions/create-log-sheet/.env_debug
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH=projects/32472615575/secrets/sa-access-google-drive-key
|
||||
LOG_FOLDER_ID=1IZToaM9K9OJXrgV05aLO5k2ZCXpdlJzX
|
||||
MEETING_FOLDER_ID=1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw
|
||||
HUBSPOT_COMPANY_URL=https://app-na2.hubspot.com/contacts/242960467/record/0-2
|
||||
MODE=dev
|
||||
5
functions/create-log-sheet/.env_dev
Executable file
5
functions/create-log-sheet/.env_dev
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH: projects/32472615575/secrets/sa-access-google-drive-key
|
||||
LOG_FOLDER_ID: 1IZToaM9K9OJXrgV05aLO5k2ZCXpdlJzX
|
||||
MEETING_FOLDER_ID: 1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw
|
||||
HUBSPOT_COMPANY_URL: https://app-na2.hubspot.com/contacts/242960467/record/0-2
|
||||
MODE: dev
|
||||
5
functions/create-log-sheet/.env_prod
Executable file
5
functions/create-log-sheet/.env_prod
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
KEY_PATH: projects/570987459910/secrets/sa-create-minutes-key
|
||||
LOG_FOLDER_ID: 1arL6AxpvA7N6Umg4wdrdAcRWBdKc-Jfb
|
||||
MEETING_FOLDER_ID: 0AGT_1dSq66qYUk9PVA
|
||||
HUBSPOT_COMPANY_URL: https://app.hubspot.com/contacts/22400567/record/0-2
|
||||
MODE: production
|
||||
33
functions/create-log-sheet/_scripts/deploy_dev.sh
Executable file
33
functions/create-log-sheet/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-create-log-sheet"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
218
functions/create-log-sheet/source/main.py
Executable file
218
functions/create-log-sheet/source/main.py
Executable file
|
|
@ -0,0 +1,218 @@
|
|||
import functions_framework
|
||||
from google.cloud import secretmanager
|
||||
from google.oauth2 import service_account
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
|
||||
SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]
|
||||
HEADER_VALUES = ["タイムスタンプ","商談日", "タイトル", "登録先企業","担当者", "ミーティングURL", "議事録URL", "HubSpot会社概要URL"]
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
# POSTリクエストの処理
|
||||
if request.method != 'POST':
|
||||
return ('', 405, {'Allow': 'POST', 'Content-Type': 'application/json'}) # メソッドがPOSTでない場合は405エラーを返す
|
||||
|
||||
"""Shows basic usage of the Drive Activity API.
|
||||
|
||||
Prints information about the last 10 events that occured the user's Drive.
|
||||
"""
|
||||
try:
|
||||
log_folder_id = os.getenv("LOG_FOLDER_ID") # 共有ドライブID
|
||||
meeting_folder_id = os.getenv("MEETING_FOLDER_ID") # ミーティングフォルダID
|
||||
mode = os.getenv("MODE") # モード(devまたはprod)
|
||||
|
||||
service_account_info = get_service_account_info()
|
||||
# 認証
|
||||
credentials = get_credentials(service_account_info)
|
||||
|
||||
# APIクライアントの構築
|
||||
drive_service = build("drive", "v3", credentials=credentials)
|
||||
sheet_service = build("sheets", "v4", credentials=credentials)
|
||||
|
||||
|
||||
# 現在日時をJSTに変換
|
||||
jst_now = datetime.now(timezone.utc).astimezone(timezone(timedelta(hours=9)))
|
||||
# JSTの現在日時を文字列に変換
|
||||
ym_str = jst_now.strftime("%Y%m")
|
||||
y_str = jst_now.strftime("%Y")
|
||||
|
||||
|
||||
# 年別のフォルダを検索
|
||||
target_folder = get_directory_files_dev(drive_service, log_folder_id, y_str) if mode == "dev" else get_directory_files_prod(drive_service, meeting_folder_id, log_folder_id, y_str)
|
||||
print("target_folder", target_folder)
|
||||
|
||||
year_folder_id = None
|
||||
if not target_folder:
|
||||
# フォルダが存在しない場合は新規作成
|
||||
year_folder_id = create_new_folder(drive_service, log_folder_id, y_str)
|
||||
else:
|
||||
# フォルダが存在する場合はそのIDを使用
|
||||
year_folder_id = target_folder[0]['id']
|
||||
print("年別のフォルダID:", year_folder_id)
|
||||
|
||||
# スプレッドシートを作成
|
||||
spreadsheet_id = create_new_spreadsheet(drive_service, year_folder_id, ym_str)
|
||||
print("スプレッドシートID:", spreadsheet_id)
|
||||
# 注意事項追加
|
||||
append_log_to_sheet(sheet_service, spreadsheet_id, ["※シート名変更厳禁"])
|
||||
# ヘッダーを追加
|
||||
append_log_to_sheet(sheet_service, spreadsheet_id, HEADER_VALUES)
|
||||
|
||||
|
||||
|
||||
return (json.dumps({"status": "success"}, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
|
||||
except HttpError as error:
|
||||
# TODO(developer) - Handleerrors from drive activity API.
|
||||
print(f"An error occurred: {error}")
|
||||
|
||||
|
||||
#
|
||||
# SecretManagerから秘密鍵を取得
|
||||
#
|
||||
def get_service_account_info():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# 秘密鍵取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# 秘密鍵の値をデコード
|
||||
secret_key = response.payload.data.decode("UTF-8")
|
||||
return json.loads(secret_key)
|
||||
|
||||
# Google Drive認証
|
||||
def get_credentials(service_account_info):
|
||||
credentials = service_account.Credentials.from_service_account_info(
|
||||
service_account_info,
|
||||
scopes=SCOPES
|
||||
)
|
||||
return credentials
|
||||
|
||||
|
||||
# 開発用マイドライブからのファイルを取得
|
||||
def get_directory_files_dev(service,shared_folder_id, filename):
|
||||
"""
|
||||
対象のディレクトリ配下からファイル名で検索した結果を配列で返す
|
||||
:param filename: ファイル名
|
||||
:param directory_id: ディレクトリID
|
||||
:param pages_max: 最大ページ探索数
|
||||
:return: ファイルリスト
|
||||
"""
|
||||
items = []
|
||||
page = 0
|
||||
pages_max = 10 # 最大ページ数
|
||||
while True:
|
||||
page += 1
|
||||
if page == pages_max:
|
||||
break
|
||||
results = service.files().list(
|
||||
corpora="user",
|
||||
includeItemsFromAllDrives=True,
|
||||
includeTeamDriveItems=True,
|
||||
q=f"'{shared_folder_id}' in parents and name = '{filename}' and trashed = false",
|
||||
supportsAllDrives=True,
|
||||
pageSize=10,
|
||||
fields="nextPageToken, files(id, name)").execute()
|
||||
items += results.get("files", [])
|
||||
|
||||
page_token = results.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
return items
|
||||
|
||||
# 本番用共有ドライブからのファイルを取得
|
||||
def get_directory_files_prod(service,shared_folder_id,sub_folder_id,filename):
|
||||
"""
|
||||
対象のディレクトリ配下からファイル名で検索した結果を配列で返す
|
||||
:param filename: ファイル名
|
||||
:param directory_id: ディレクトリID
|
||||
:param pages_max: 最大ページ探索数
|
||||
:return: ファイルリスト
|
||||
"""
|
||||
items = []
|
||||
page = 0
|
||||
pages_max = 10 # 最大ページ数
|
||||
while True:
|
||||
page += 1
|
||||
if page == pages_max:
|
||||
break
|
||||
results = service.files().list(
|
||||
corpora="drive",
|
||||
driveId=shared_folder_id,
|
||||
includeItemsFromAllDrives=True,
|
||||
includeTeamDriveItems=True,
|
||||
q=f"'{sub_folder_id}' in parents and name = '{filename}' and trashed = false",
|
||||
supportsAllDrives=True,
|
||||
pageSize=10,
|
||||
fields="nextPageToken, files(id, name, parents)").execute()
|
||||
items += results.get("files", [])
|
||||
|
||||
page_token = results.get('nextPageToken', None)
|
||||
if page_token is None:
|
||||
break
|
||||
return items
|
||||
|
||||
def create_new_folder(service, sub_folder_id, title):
|
||||
"""
|
||||
Google Drive APIを使用して新しいフォルダを作成する
|
||||
:param service: Google Drive APIのサービスオブジェクト
|
||||
:param title: フォルダのタイトル
|
||||
:return: 作成したフォルダのID
|
||||
"""
|
||||
file_metadata = {
|
||||
"name": title,
|
||||
"parents": [sub_folder_id], # 共有ドライブのIDを指定
|
||||
"mimeType": "application/vnd.google-apps.folder",
|
||||
}
|
||||
|
||||
result = service.files().create(body=file_metadata, fields="id", supportsAllDrives=True).execute()
|
||||
return result.get('id')
|
||||
|
||||
|
||||
def create_new_spreadsheet(service,folder_id,title):
|
||||
"""
|
||||
Google Sheets APIを使用して新しいスプレッドシートを作成する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param title: スプレッドシートのタイトル
|
||||
:return: 作成したスプレッドシートのID
|
||||
"""
|
||||
file_metadata = {
|
||||
'name': title,
|
||||
'parents': [folder_id], # 作成したフォルダのIDを指定
|
||||
'mimeType': 'application/vnd.google-apps.spreadsheet',
|
||||
}
|
||||
result = (
|
||||
service.files()
|
||||
.create(body=file_metadata, fields="id", supportsAllDrives=True)
|
||||
.execute()
|
||||
)
|
||||
return result.get("id")
|
||||
|
||||
|
||||
def append_log_to_sheet(service, spreadsheet_id, row_data):
|
||||
"""
|
||||
Google Sheets APIを使用してスプレッドシートにログを追加する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param spreadsheet_id: スプレッドシートのID
|
||||
:param row_data: 追加するログデータ(リスト形式)
|
||||
"""
|
||||
body = {
|
||||
'values': [row_data]
|
||||
}
|
||||
|
||||
# スプレッドシートにログを追加
|
||||
result = service.spreadsheets().values().append(
|
||||
spreadsheetId=spreadsheet_id,
|
||||
range='Sheet1',
|
||||
valueInputOption="USER_ENTERED",
|
||||
insertDataOption='INSERT_ROWS',
|
||||
body=body,
|
||||
).execute()
|
||||
print(f"{result.get('updates').get('updatedCells')} cells appended.")
|
||||
|
||||
5
functions/create-log-sheet/source/requirements.txt
Executable file
5
functions/create-log-sheet/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
google-cloud-secret-manager
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
5
functions/export-companies-to-gcs/.env_debug
Executable file
5
functions/export-companies-to-gcs/.env_debug
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID=datacom-poc
|
||||
LOCATION=asia-northeast1
|
||||
BUCKET=meeting-report-data
|
||||
OBJECT=master/mst_company.csv
|
||||
KEY_PATH=projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
5
functions/export-companies-to-gcs/.env_dev
Executable file
5
functions/export-companies-to-gcs/.env_dev
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: datacom-poc
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-report-data
|
||||
OBJECT: master/mst_company.csv
|
||||
KEY_PATH: projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
5
functions/export-companies-to-gcs/.env_prod
Executable file
5
functions/export-companies-to-gcs/.env_prod
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: rational-timing-443808-u0
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-data
|
||||
OBJECT: master/mst_company.csv
|
||||
KEY_PATH: projects/570987459910/secrets/mrt-hubspot-accesstoken
|
||||
87
functions/export-companies-to-gcs/source/main.py
Executable file
87
functions/export-companies-to-gcs/source/main.py
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
import functions_framework
|
||||
from google.cloud import storage, secretmanager
|
||||
import os
|
||||
import hubspot
|
||||
from hubspot.crm.objects.meetings import ApiException
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
|
||||
cs_client = storage.Client()
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
try:
|
||||
# 会社一覧取得
|
||||
companies = fetch_all_companies()
|
||||
# メモリ上で CSV を生成
|
||||
csv_buffer = io.StringIO()
|
||||
writer = csv.writer(csv_buffer)
|
||||
# ヘッダー行
|
||||
writer.writerow(["company_id", "company_name"])
|
||||
# 各行を書き込み
|
||||
for row in companies:
|
||||
company_id = row['properties']['hs_object_id']
|
||||
company_name = row['properties']['name']
|
||||
writer.writerow([company_id, company_name])
|
||||
|
||||
# Cloud Storage にアップロード
|
||||
upload_to_gcs(csv_buffer)
|
||||
return 'success', 200
|
||||
except ApiException as e:
|
||||
print("Exception when calling basic_api->create: %s\n" % e)
|
||||
return (json.dumps("", ensure_ascii=False), 500, {"Content-Type": "application/json"})
|
||||
|
||||
def fetch_all_companies():
|
||||
"""
|
||||
Companies API の get_page をページネーション付きで呼び出し、
|
||||
全オブジェクトをリストで返す。
|
||||
"""
|
||||
access_key = get_access_key() # Secret Manager からアクセストークンを取得
|
||||
hs_client = hubspot.Client.create(access_token=access_key)
|
||||
|
||||
all_companies = []
|
||||
after = None
|
||||
limit = 100 # 1 回あたりの取得件数(最大 100)
|
||||
|
||||
while True:
|
||||
# get_page の基本呼び出し
|
||||
response = hs_client.crm.companies.basic_api.get_page(
|
||||
limit=limit,
|
||||
archived=False,
|
||||
after=after
|
||||
)
|
||||
|
||||
# レスポンスから companies の配列を追加
|
||||
if response.results:
|
||||
all_companies.extend([c.to_dict() for c in response.results])
|
||||
|
||||
# 次ページがない場合はループ終了
|
||||
paging = response.paging
|
||||
if not paging or not paging.next or not paging.next.after:
|
||||
break
|
||||
|
||||
# next.after をセットして次ループへ
|
||||
after = paging.next.after
|
||||
|
||||
return all_companies
|
||||
|
||||
def upload_to_gcs(data):
|
||||
"""
|
||||
メモリ上の CSV データを Cloud Storage にアップロード
|
||||
"""
|
||||
bucket = cs_client.bucket(os.getenv("BUCKET"))
|
||||
blob = bucket.blob(os.getenv("OBJECT"))
|
||||
blob.upload_from_string(data.getvalue(), content_type='text/csv')
|
||||
|
||||
#
|
||||
# SecretManagerからアクセストークンを取得
|
||||
#
|
||||
def get_access_key():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# アクセストークン取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# アクセストークンをデコード
|
||||
access_token = response.payload.data.decode("UTF-8")
|
||||
return access_token
|
||||
5
functions/export-companies-to-gcs/source/requirements.txt
Executable file
5
functions/export-companies-to-gcs/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
Flask
|
||||
google-cloud-storage
|
||||
google-cloud-secret-manager
|
||||
hubspot-api-client
|
||||
5
functions/export-owners-to-gcs/.env_debug
Executable file
5
functions/export-owners-to-gcs/.env_debug
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID=datacom-poc
|
||||
LOCATION=asia-northeast1
|
||||
BUCKET=meeting-report-data
|
||||
OBJECT=master/mst_owner.csv
|
||||
KEY_PATH=projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
5
functions/export-owners-to-gcs/.env_dev
Executable file
5
functions/export-owners-to-gcs/.env_dev
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: datacom-poc
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-report-data
|
||||
OBJECT: master/mst_owner.csv
|
||||
KEY_PATH: projects/32472615575/secrets/mrt-hubspot-accesstoken
|
||||
5
functions/export-owners-to-gcs/.env_prod
Executable file
5
functions/export-owners-to-gcs/.env_prod
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROJECT_ID: rational-timing-443808-u0
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-data
|
||||
OBJECT: master/mst_owner.csv
|
||||
KEY_PATH: projects/570987459910/secrets/mrt-hubspot-accesstoken
|
||||
90
functions/export-owners-to-gcs/source/main.py
Executable file
90
functions/export-owners-to-gcs/source/main.py
Executable file
|
|
@ -0,0 +1,90 @@
|
|||
import functions_framework
|
||||
from google.cloud import storage, secretmanager
|
||||
import os
|
||||
import hubspot
|
||||
from hubspot.crm.objects.meetings import ApiException
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
|
||||
cs_client = storage.Client()
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
try:
|
||||
# 会社一覧取得
|
||||
owners = fetch_all_owners()
|
||||
# メモリ上で CSV を生成
|
||||
csv_buffer = io.StringIO()
|
||||
writer = csv.writer(csv_buffer)
|
||||
# ヘッダー行
|
||||
writer.writerow(["id", "email"])
|
||||
# 各行を書き込み
|
||||
for row in owners:
|
||||
user_id = row['id']
|
||||
email = row['email']
|
||||
writer.writerow([user_id, email])
|
||||
|
||||
# Cloud Storage にアップロード
|
||||
upload_to_gcs(csv_buffer)
|
||||
return (json.dumps('', ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
except ApiException as e:
|
||||
print("Exception when calling basic_api->create: %s\n" % e)
|
||||
|
||||
|
||||
return (json.dumps("", ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
|
||||
def fetch_all_owners():
|
||||
"""
|
||||
Companies API の get_page をページネーション付きで呼び出し、
|
||||
全オブジェクトをリストで返す。
|
||||
"""
|
||||
access_key = get_access_key() # Secret Manager からアクセストークンを取得
|
||||
hs_client = hubspot.Client.create(access_token=access_key)
|
||||
|
||||
all_owners = []
|
||||
after = None
|
||||
limit = 100 # 1 回あたりの取得件数(最大 100)
|
||||
|
||||
while True:
|
||||
# get_page の基本呼び出し
|
||||
response = hs_client.crm.owners.owners_api.get_page(
|
||||
limit=limit,
|
||||
archived=False,
|
||||
after=after
|
||||
)
|
||||
|
||||
# レスポンスから companies の配列を追加
|
||||
if response.results:
|
||||
all_owners.extend([c.to_dict() for c in response.results])
|
||||
|
||||
# 次ページがない場合はループ終了
|
||||
paging = response.paging
|
||||
if not paging or not paging.next or not paging.next.after:
|
||||
break
|
||||
|
||||
# next.after をセットして次ループへ
|
||||
after = paging.next.after
|
||||
|
||||
return all_owners
|
||||
|
||||
def upload_to_gcs(data):
|
||||
"""
|
||||
メモリ上の CSV データを Cloud Storage にアップロード
|
||||
"""
|
||||
bucket = cs_client.bucket(os.getenv("BUCKET"))
|
||||
blob = bucket.blob(os.getenv("OBJECT"))
|
||||
blob.upload_from_string(data.getvalue(), content_type='text/csv')
|
||||
|
||||
#
|
||||
# SecretManagerからアクセストークンを取得
|
||||
#
|
||||
def get_access_key():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# アクセストークン取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# アクセストークンをデコード
|
||||
access_token = response.payload.data.decode("UTF-8")
|
||||
return access_token
|
||||
5
functions/export-owners-to-gcs/source/requirements.txt
Executable file
5
functions/export-owners-to-gcs/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
Flask
|
||||
google-cloud-storage
|
||||
google-cloud-secret-manager
|
||||
hubspot-api-client
|
||||
3
functions/generate-meeting-minutes/.env_debug
Executable file
3
functions/generate-meeting-minutes/.env_debug
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
MIITEL_URL=https://datacom.miitel.jp/
|
||||
PROJECT_ID=datacom-poc
|
||||
MODEL_ID=gemini-2.5-flash
|
||||
3
functions/generate-meeting-minutes/.env_dev
Executable file
3
functions/generate-meeting-minutes/.env_dev
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
MIITEL_URL: https://datacom.miitel.jp/
|
||||
PROJECT_ID: datacom-poc
|
||||
MODEL_ID: gemini-2.5-flash
|
||||
3
functions/generate-meeting-minutes/.env_prod
Executable file
3
functions/generate-meeting-minutes/.env_prod
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
MIITEL_URL: https://datacom.miitel.jp/
|
||||
PROJECT_ID: rational-timing-443808-u0
|
||||
MODEL_ID: gemini-2.5-flash
|
||||
35
functions/generate-meeting-minutes/_scripts/deploy_dev.sh
Executable file
35
functions/generate-meeting-minutes/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-generate-meeting-minutes"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--cpu=0.5 \
|
||||
--memory=1Gi \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
132
functions/generate-meeting-minutes/source/main.py
Executable file
132
functions/generate-meeting-minutes/source/main.py
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
import functions_framework
|
||||
import vertexai
|
||||
from vertexai.generative_models import GenerativeModel, ChatSession
|
||||
from google.cloud import storage
|
||||
from google.cloud import secretmanager
|
||||
import json
|
||||
import requests
|
||||
import os
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import gzip
|
||||
|
||||
|
||||
# Storage クライアントを作成
|
||||
storage_client = storage.Client()
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
# POSTリクエストの処理
|
||||
if request.method != 'POST':
|
||||
return ({'error': 'Method not allowed'}, 405, {'Content-Type': 'application/json'})
|
||||
try:
|
||||
request_json = request.get_json()
|
||||
print(request_json)
|
||||
|
||||
project_id = os.getenv("PROJECT_ID")
|
||||
miitel_url = os.getenv("MIITEL_URL")
|
||||
|
||||
video_info = request_json["video"]
|
||||
|
||||
access_permission = video_info["access_permission"]
|
||||
video_id = video_info["id"] # 会議履歴ID
|
||||
host_name = video_info["host"]["user_name"] # ホストユーザー名
|
||||
host_id = video_info["host"]["login_id"] # ホストユーザーID
|
||||
starts_at = video_info["starts_at"] # 開始日時
|
||||
ends_at = video_info["ends_at"] # 終了日時
|
||||
|
||||
video_url = miitel_url + "app/video/" + video_id # 会議履歴URL
|
||||
title = video_info["title"] # 会議タイトル
|
||||
print("会議タイトル",title)
|
||||
|
||||
# 閲覧制限のない会議のみ生成
|
||||
if access_permission != "EVERYONE":
|
||||
return (json.dumps({"status": "end"}, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
|
||||
# 社外ミーティングのみ議事録作成
|
||||
if "様" not in title or "社内" in title:
|
||||
return (json.dumps({"status": "end"}, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
|
||||
# 議事録ファイル名
|
||||
jst_date_str = generate_jst_date(starts_at) # 開始日時をJSTに変換
|
||||
file_name = f"{jst_date_str} {title} {host_name}"
|
||||
print(file_name)
|
||||
# 議事録作成
|
||||
speech_recognition = video_info["speech_recognition"]["raw"] # 文字起こしデータ
|
||||
minutes_text = create_minutes(project_id,speech_recognition)
|
||||
print("議事録作成完了")
|
||||
|
||||
# テキスト内容をセット
|
||||
minutes = f"会議履歴URL:{video_url}\n"
|
||||
minutes += f"担当者:{host_name}\n\n"
|
||||
minutes += minutes_text
|
||||
|
||||
response_data = {
|
||||
"status": "next", # ステータス
|
||||
"title": title, # 会議タイトル
|
||||
"host_id": host_id, # ホストユーザーID
|
||||
"host_name": host_name, # ホストユーザー名
|
||||
"video_url": video_url, # 会議履歴URL
|
||||
"starts_at": starts_at, # 開始日時
|
||||
"ends_at": ends_at, # 終了日時
|
||||
"file_name": file_name, # 議事録ファイル名
|
||||
"minutes": minutes, # 議事録内容
|
||||
}
|
||||
|
||||
return (json.dumps(response_data, ensure_ascii=False), 200, {"Content-Type": "application/json"})
|
||||
except Exception as e:
|
||||
# エラー
|
||||
error_response = {
|
||||
"error": str(e) #エラー内容
|
||||
}
|
||||
print(str(e))
|
||||
return json.dumps(error_response), 500, {'Content-Type': 'application/json'} #エラー
|
||||
|
||||
|
||||
def generate_jst_date(starts_at):
|
||||
|
||||
# UTCの文字列をdatetimeオブジェクトに変換
|
||||
utc_datetime = datetime.fromisoformat(starts_at)
|
||||
|
||||
# JSTへの変換
|
||||
jst_timezone = timezone(timedelta(hours=9)) # JSTはUTC+9
|
||||
jst_datetime = utc_datetime.astimezone(jst_timezone)
|
||||
|
||||
# yyyy-MM-dd形式にフォーマット
|
||||
jst_date_str = jst_datetime.strftime("%Y年%m月%d日")
|
||||
return jst_date_str
|
||||
|
||||
|
||||
def create_minutes(project_id,speech_recognition):
|
||||
location = "us-central1"
|
||||
model_id = os.getenv("MODEL_ID")
|
||||
# print("モデルID:", model_id)
|
||||
|
||||
vertexai.init(project=project_id, location=location)
|
||||
model = GenerativeModel(model_id)
|
||||
# print("モデル初期化完了")
|
||||
|
||||
prompt = f"""
|
||||
あなたは議事録作成のプロフェッショナルです。以下の「文字起こし結果」は営業マンが録音した商談の文字起こしです。以下の制約条件に従い、最高の商談報告の議事録を作成してください。
|
||||
|
||||
制約条件:
|
||||
1. 文字起こし結果にはAIによる書き起こしミスがある可能性を考慮してください。
|
||||
2. 冒頭に主要な「決定事項」と「アクションアイテム」をまとめてください。
|
||||
3. 議論のポイントを議題ごとに要約してください。
|
||||
4. 見出しや箇条書きを用いて、情報が探しやすい構造で簡潔かつ明瞭に記述してください。
|
||||
5. 要約は500文字以内に収めてください。
|
||||
6. 箇条書き形式で簡潔にまとめてください。
|
||||
7. マークダウン記法は使わず、各項目を「■」や「・」等を使って見やすくしてください。
|
||||
|
||||
文字起こし結果:
|
||||
{speech_recognition}
|
||||
"""
|
||||
|
||||
|
||||
# print("-------------プロンプト-------------")
|
||||
# print(prompt[:1000])
|
||||
# print("-------------議事録作成-------------")
|
||||
response = model.generate_content(prompt)
|
||||
# print(response.text)
|
||||
return response.text
|
||||
|
||||
5
functions/generate-meeting-minutes/source/requirements.txt
Executable file
5
functions/generate-meeting-minutes/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
google-cloud-storage
|
||||
google-cloud-aiplatform
|
||||
google-cloud-secret-manager
|
||||
pydrive2
|
||||
4
functions/trigger-minutes-workflow-from-miitel/.env_debug
Executable file
4
functions/trigger-minutes-workflow-from-miitel/.env_debug
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
PROJECT_ID=datacom-poc
|
||||
LOCATION=asia-northeast1
|
||||
BUCKET=meeting-report-data
|
||||
WORKFLOW=mrt-workflow-create-minutes
|
||||
4
functions/trigger-minutes-workflow-from-miitel/.env_dev
Executable file
4
functions/trigger-minutes-workflow-from-miitel/.env_dev
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
PROJECT_ID: datacom-poc
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-report-data
|
||||
WORKFLOW: mrt-workflow-create-minutes
|
||||
4
functions/trigger-minutes-workflow-from-miitel/.env_prod
Executable file
4
functions/trigger-minutes-workflow-from-miitel/.env_prod
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
PROJECT_ID: rational-timing-443808-u0
|
||||
LOCATION: asia-northeast1
|
||||
BUCKET: meeting-data
|
||||
WORKFLOW: mrt-workflow-create-minutes
|
||||
33
functions/trigger-minutes-workflow-from-miitel/_scripts/deploy_dev.sh
Executable file
33
functions/trigger-minutes-workflow-from-miitel/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-trigger-minutes-workflow-from-miitel"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
75
functions/trigger-minutes-workflow-from-miitel/source/main.py
Executable file
75
functions/trigger-minutes-workflow-from-miitel/source/main.py
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
import functions_framework
|
||||
from google.cloud import storage
|
||||
from google.cloud.workflows import executions_v1
|
||||
from google.cloud.workflows.executions_v1.types import Execution
|
||||
import json
|
||||
import os
|
||||
import gzip
|
||||
|
||||
|
||||
# Storage クライアントを作成
|
||||
cs_client = storage.Client()
|
||||
wf_client = executions_v1.ExecutionsClient()
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
# POSTリクエストの処理
|
||||
if request.method != 'POST':
|
||||
# 他のメソッドに対するエラーレスポンス
|
||||
return ({'error': 'Method not allowed'}, 405)
|
||||
|
||||
try:
|
||||
request_json = request.get_json()
|
||||
print(request_json)
|
||||
|
||||
|
||||
if "challenge" in request_json:
|
||||
# MiiTelのチャレンジリクエストに対する応答
|
||||
return (request_json["challenge"], 200, {'Content-Type':'text/plain'})
|
||||
|
||||
project_id = os.getenv("PROJECT_ID")
|
||||
bucket_name = os.getenv("BUCKET") # 共有ドライブID
|
||||
location = os.getenv("LOCATION") # ワークフローのロケーション
|
||||
workflow = os.getenv("WORKFLOW") # ワークフロー名
|
||||
|
||||
# デバッグ用に保存
|
||||
save_to_gcs(bucket_name,request_json)
|
||||
|
||||
# ワークフロー呼び出し
|
||||
argument = json.dumps({"video": request_json["video"]})
|
||||
execution = Execution(argument=argument)
|
||||
parent = f"projects/{project_id}/locations/{location}/workflows/{workflow}"
|
||||
print(parent)
|
||||
response = wf_client.create_execution(request={"parent": parent, "execution": execution})
|
||||
print(f"Workflow execution started: {response.name}")
|
||||
|
||||
return (json.dumps({}), 200, {'Content-Type': 'application/json'})
|
||||
except Exception as e:
|
||||
# エラー
|
||||
error_response = {
|
||||
"error": str(e) #エラー内容
|
||||
}
|
||||
print(str(e))
|
||||
return json.dumps(error_response), 500, {'Content-Type': 'application/json'} #エラー
|
||||
|
||||
|
||||
|
||||
|
||||
def save_to_gcs(bucket_name,request_json):
|
||||
file_name = request_json["video"]["id"] + ".json.gz"
|
||||
|
||||
bucket = cs_client.bucket(bucket_name)
|
||||
|
||||
# GCS バケットのブロブを取得
|
||||
blob = bucket.blob(f"request_log/{file_name}")
|
||||
|
||||
|
||||
# JSONを文字列に変換
|
||||
json_string = json.dumps(request_json)
|
||||
|
||||
# Gzip圧縮
|
||||
compressed_data = gzip.compress(json_string.encode('utf-8'))
|
||||
|
||||
# 圧縮されたデータをアップロード
|
||||
blob.upload_from_string(compressed_data, content_type='application/gzip')
|
||||
|
||||
4
functions/trigger-minutes-workflow-from-miitel/source/requirements.txt
Executable file
4
functions/trigger-minutes-workflow-from-miitel/source/requirements.txt
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
functions-framework==3.*
|
||||
Flask
|
||||
google-cloud-storage
|
||||
google-cloud-workflows
|
||||
2
functions/upload-minutes-to-drive/.env_debug
Executable file
2
functions/upload-minutes-to-drive/.env_debug
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
KEY_PATH=projects/570987459910/secrets/sa-create-minutes-key
|
||||
FOLDER_ID=0AGT_1dSq66qYUk9PVA
|
||||
2
functions/upload-minutes-to-drive/.env_dev
Executable file
2
functions/upload-minutes-to-drive/.env_dev
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
KEY_PATH: projects/32472615575/secrets/sa-access-google-drive-key
|
||||
FOLDER_ID: 1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw
|
||||
2
functions/upload-minutes-to-drive/.env_prod
Executable file
2
functions/upload-minutes-to-drive/.env_prod
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
KEY_PATH: projects/570987459910/secrets/sa-create-minutes-key
|
||||
FOLDER_ID: 0AGT_1dSq66qYUk9PVA
|
||||
33
functions/upload-minutes-to-drive/_scripts/deploy_dev.sh
Executable file
33
functions/upload-minutes-to-drive/_scripts/deploy_dev.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# プロジェクトIDを設定
|
||||
PROJECT_ID="datacom-poc"
|
||||
|
||||
# デプロイする関数名
|
||||
FUNCTION_NAME="mrt-create-minutes"
|
||||
|
||||
# 関数のエントリポイント
|
||||
ENTRY_POINT="handle_request"
|
||||
|
||||
# ランタイム
|
||||
RUNTIME="python312"
|
||||
|
||||
# リージョン
|
||||
REGION="asia-northeast1"
|
||||
|
||||
# 環境変数ファイル
|
||||
ENV_VARS_FILE=".env_dev"
|
||||
|
||||
gcloud auth application-default set-quota-project $PROJECT_ID
|
||||
gcloud config set project $PROJECT_ID
|
||||
|
||||
# デプロイコマンド
|
||||
gcloud functions deploy $FUNCTION_NAME \
|
||||
--gen2 \
|
||||
--region $REGION \
|
||||
--runtime $RUNTIME \
|
||||
--source=./source \
|
||||
--trigger-http \
|
||||
--no-allow-unauthenticated \
|
||||
--entry-point $ENTRY_POINT \
|
||||
--env-vars-file $ENV_VARS_FILE
|
||||
128
functions/upload-minutes-to-drive/source/main.py
Executable file
128
functions/upload-minutes-to-drive/source/main.py
Executable file
|
|
@ -0,0 +1,128 @@
|
|||
import functions_framework
|
||||
from google.cloud import secretmanager
|
||||
from google.oauth2 import service_account
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
import json
|
||||
import os
|
||||
|
||||
SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]
|
||||
|
||||
sm_client = secretmanager.SecretManagerServiceClient()
|
||||
|
||||
@functions_framework.http
|
||||
def handle_request(request):
|
||||
# POSTリクエストの処理
|
||||
if request.method != 'POST':
|
||||
# 他のメソッドに対するエラーレスポンス
|
||||
return ({'error': 'Method not allowed'}, 405)
|
||||
|
||||
try:
|
||||
request_json = request.get_json()
|
||||
print(request_json)
|
||||
|
||||
folder_id = os.getenv("FOLDER_ID") # 共有ドライブID
|
||||
|
||||
file_name = request_json["file_name"] # 会議タイトル
|
||||
minutes = request_json["minutes"] # 議事録
|
||||
|
||||
|
||||
# Secret Manager からサービスアカウントJSON文字列を取得
|
||||
service_account_info = get_service_account_info()
|
||||
# 認証
|
||||
credentials = get_credentials(service_account_info)
|
||||
|
||||
# APIクライアントの構築
|
||||
drive_service = build("drive", "v3", credentials=credentials)
|
||||
docs_service = build("docs", "v1", credentials=credentials)
|
||||
|
||||
# ファイル作成
|
||||
document_id = create_new_document(drive_service, folder_id, file_name)
|
||||
print(f"Created document with ID: {document_id}")
|
||||
|
||||
# テキスト内容をセット
|
||||
append_minutes_to_doc(docs_service, document_id, minutes)
|
||||
|
||||
response_data = {
|
||||
"document_id": document_id, # 作成したドキュメントのID
|
||||
}
|
||||
|
||||
return json.dumps(response_data) , 200, {"Content-Type": "application/json"}
|
||||
except Exception as e:
|
||||
# エラー
|
||||
error_response = {
|
||||
"error": str(e) #エラー内容
|
||||
}
|
||||
print(str(e))
|
||||
return json.dumps(error_response), 500, {'Content-Type': 'application/json'} #エラー
|
||||
|
||||
|
||||
|
||||
#
|
||||
# SecretManagerから秘密鍵を取得
|
||||
#
|
||||
def get_service_account_info():
|
||||
key_path = os.getenv('KEY_PATH') + "/versions/1"
|
||||
# 秘密鍵取得
|
||||
response = sm_client.access_secret_version(name=key_path)
|
||||
# 秘密鍵の値をデコード
|
||||
secret_key = response.payload.data.decode("UTF-8")
|
||||
return json.loads(secret_key)
|
||||
|
||||
# Google Drive認証
|
||||
def get_credentials(service_account_info):
|
||||
credentials = service_account.Credentials.from_service_account_info(
|
||||
service_account_info,
|
||||
scopes=SCOPES
|
||||
)
|
||||
return credentials
|
||||
|
||||
|
||||
def create_new_document(service,folder_id,title):
|
||||
"""
|
||||
Google Sheets APIを使用して新しいスプレッドシートを作成する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param title: スプレッドシートのタイトル
|
||||
:return: 作成したスプレッドシートのID
|
||||
"""
|
||||
file_metadata = {
|
||||
'name': title,
|
||||
'parents': [folder_id], # 作成したフォルダのIDを指定
|
||||
'mimeType': 'application/vnd.google-apps.document',
|
||||
}
|
||||
result = (
|
||||
service.files()
|
||||
.create(body=file_metadata, fields="id", supportsAllDrives=True)
|
||||
.execute()
|
||||
)
|
||||
return result.get("id")
|
||||
|
||||
|
||||
def append_minutes_to_doc(service, document_id, minutes):
|
||||
"""
|
||||
Google Sheets APIを使用してスプレッドシートにログを追加する
|
||||
:param service: Google Sheets APIのサービスオブジェクト
|
||||
:param spreadsheet_id: スプレッドシートのID
|
||||
:param row_data: 追加するログデータ(リスト形式)
|
||||
"""
|
||||
requests = [
|
||||
{
|
||||
'insertText': {
|
||||
'location': {
|
||||
'index': 1,
|
||||
},
|
||||
'text': minutes
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
body = {
|
||||
'requests': requests
|
||||
}
|
||||
|
||||
# スプレッドシートにログを追加
|
||||
result = service.documents().batchUpdate(
|
||||
documentId=document_id,
|
||||
body=body,
|
||||
).execute()
|
||||
return result
|
||||
5
functions/upload-minutes-to-drive/source/requirements.txt
Executable file
5
functions/upload-minutes-to-drive/source/requirements.txt
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
functions-framework==3.*
|
||||
google-cloud-secret-manager
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
Loading…
Add table
Add a link
Reference in a new issue