-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (50 loc) · 1.87 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from argparse import ArgumentParser
from datetime import datetime, timedelta
from gmail_api import build_service, get_messages, parse_message
from openai_api import chatgpt_summary
from tqdm import tqdm
def generate_markdown_report(input_text, project_name, date):
title = f"{project_name}"
markdown_text = input_text.replace('\n', '\n\n')
markdown_content = f"# {title}\n\n## {date} 彙整報告\n\n{markdown_text}"
file_name = f"{project_name}.md"
with open(file_name, "w", encoding="utf-8") as file:
file.write(markdown_content)
return file_name
def main(project_name, time_length):
current_date = datetime.now()
after_date = current_date - timedelta(days=time_length)
after_date = after_date.strftime('%Y/%m/%d')
service = build_service()
messages = get_messages(
service,
after_date=after_date,
subject_filter=project_name
)
results = [
parse_message(service, msg['id'])
for msg in tqdm(messages)
]
# 調用 OpenAI API
summary = chatgpt_summary(results)
summary = f'{summary}\n\n---\n\n本日共彙整郵件: {len(results)} 封\n\n以上報告由 OpenAI GPT-3.5 Turbo 模型自動生成。'
# 生成 Markdown 報告
markdown_file = generate_markdown_report(
summary, project_name, current_date.strftime('%Y-%m-%d'))
print(f"Markdown 文件已生成: {markdown_file}")
if __name__ == "__main__":
parser = ArgumentParser(description="Generate a project update report.")
parser.add_argument(
"--project_name",
type=str,
help="The name of the project to track.",
default="Albumentations"
)
parser.add_argument(
"--time_length",
type=int,
help="The time length (in days) to track updates.",
default=1
)
args = parser.parse_args()
main(args.project_name, args.time_length)