-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbatch_main.py
43 lines (31 loc) · 1.26 KB
/
batch_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from dotenv import load_dotenv
from gmail_api.gmail_service import GmailService
from pipelines.pipeline import pipeline
from utils.configuration import Config
from utils.db_utils import authenticate_gmail, fetch_users, insert_report
from utils.token_usage_counter import TokenUsageCounter
def main():
load_dotenv()
Config.load()
# 유저 테이블 불러오기
users = fetch_users()
# access token, refresh token 가져와서 service 객체 선언하기
for user in users:
try:
# if user["id"] != 11:
# continue
service = authenticate_gmail(user)
Config.user_upstage_api_key = user["upstage_api_key"]
# GmailService 인스턴스 생성
gmail_service = GmailService(service)
json_checklist, report = pipeline(gmail_service)
print(f"============ FINAL REPORT of {user['id']} =============")
print(report)
print("=======================================================")
if Config.config["token_tracking"]:
TokenUsageCounter.plot_token_cost()
insert_report(user["id"], report, json_checklist)
except Exception as e:
print(e)
if __name__ == "__main__":
main()