Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done auto save #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
33 changes: 23 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import argparse
import logging
import csv
import os

from src.JobTracker.utils import EmailMessage
from src.JobTracker.config import AUTO_SAVE_EMAIL
from src.JobTracker.chatbot import ChatGPT, Llama

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def process_email(email_path, model):

def process_email(email_path, output_csv, model="chatgpt"):
'''
Process the emails at the given path and return the results.

Expand All @@ -17,7 +20,7 @@ def process_email(email_path, model):
'''
em = EmailMessage(email_path)
mail_info = em.get_mail_info()
res = []
res = 0
chatbot = None
if model == "chatgpt":
chatbot = ChatGPT()
Expand All @@ -33,25 +36,35 @@ def process_email(email_path, model):
return
elif model == "llama":
chatbot = Llama()

for mail in mail_info:
state, data = chatbot.get_content(mail)
if state == 'Succeed':
res.append(data)
res += 1
cur.append(data)
if len(cur) % AUTO_SAVE_EMAIL == 0:
export_to_csv(cur, output_csv)
cur = []
if cur:
export_to_csv(cur, output_csv)
return res

def export_to_csv(data, filename):
with open(filename, mode='w', newline='', encoding='utf-8') as csvfile:
file_exists = os.path.exists(filename)
with open(filename, mode="a", newline='', encoding='utf-8') as csvfile:
fieldnames = data[0].keys()
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if not file_exists:
writer.writeheader()
for row in data:
writer.writerow(row)
logging.info(f"Processed {str(len(data))} emails and exported to CSV at {filename}.")


def main(email_path, output_csv, model):
result = process_email(email_path, model)
if result:
export_to_csv(result, output_csv)
logging.info(f"Processed emails successfully and exported to CSV at {output_csv}.")
result = process_email(email_path, output_csv, model)
if result > 0:
logging.info(f"Total {str(result)} emails Processed successfully and exported to CSV at {output_csv}.")
else:
logging.info("No emails processed.")

Expand Down
1 change: 1 addition & 0 deletions src/JobTracker/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
AUTO_SAVE_EMAIL = 20
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
MODEL = 'gpt-4-1106-preview'
LLAMA_URL = "http://127.0.0.1:11434/api/generate"
Expand Down