AIEmailAutomationUtility 0.0.13__py3-none-any.whl → 0.0.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,23 +19,23 @@ class EmailReplyAssistant:
19
19
 
20
20
  def on_text_created(self, text):
21
21
  if isinstance(text, str):
22
- print(f"\nAssistant: {text}", end="", flush=True)
22
+ logger.log(f"\nAssistant: {text}")
23
23
 
24
24
  def on_text_delta(self, delta, snapshot):
25
25
  self.delta_values.append(delta.value)
26
26
 
27
27
  def on_tool_call_created(self, tool_call):
28
- print(f"\nAssistant: {tool_call.type}\n", flush=True)
28
+ logger.log(f"\nAssistant: {tool_call.type}\n")
29
29
 
30
30
  def on_tool_call_delta(self, delta, snapshot):
31
31
  if delta.type == 'code_interpreter':
32
32
  if delta.code_interpreter.input:
33
- print(delta.code_interpreter.input, end="", flush=True)
33
+ logger.log(delta.code_interpreter.input)
34
34
  if delta.code_interpreter.outputs:
35
- print(f"\n\nOutput >", flush=True)
35
+ logger.log(f"\n\nOutput >", flush=True)
36
36
  for output in delta.code_interpreter.outputs:
37
37
  if output.type == "logs":
38
- print(output.logs, flush=True)
38
+ logger.log(output.logs, flush=True)
39
39
 
40
40
  openAI_response = ""
41
41
  client = OpenAI(api_key=openAI_key)
@@ -59,14 +59,14 @@ class EmailReplyAssistant:
59
59
 
60
60
  delta_values = event_handler.delta_values
61
61
  openAI_response = ''.join(delta_values)
62
- print(f"openAI_response:: {type(openAI_response)}")
63
- print(f"openAI_response:: {openAI_response}")
62
+ logger.log(f"openAI_response:: {type(openAI_response)}")
63
+ logger.log(f"openAI_response:: {openAI_response}")
64
64
  return {"status": "Success", "message": openAI_response}
65
65
 
66
66
  except Exception as error:
67
67
  responseStr = "<br/><br/>" + str(error)
68
68
  trace = traceback.format_exc()
69
- print(f"Exception in process_Email: {responseStr} \n {trace} \n DataType ::: {type(responseStr)}")
69
+ logger.log(f"Exception in process_Email: {responseStr} \n {trace} \n DataType ::: {type(responseStr)}")
70
70
  m = re.search(r"({.*})", str(error))
71
71
  data = ast.literal_eval(m.group(1)).get('error') if m else {}
72
72
  return {"status": "Failed", "message": data.get('message')}
@@ -88,8 +88,8 @@ class EmailReplyAssistant:
88
88
  subject=subject
89
89
  )
90
90
 
91
- # print(f"Reply_Email_Ai_Assistant response: {email_response}")
91
+ # logger.log(f"Reply_Email_Ai_Assistant response: {email_response}")
92
92
  return email_response
93
93
 
94
94
  except Exception as e:
95
- print(f"Error in Read_Email: {str(e)}")
95
+ logger.log(f"Error in Read_Email: {str(e)}")
@@ -7,7 +7,7 @@ from flask import Flask,request
7
7
 
8
8
  class Email_Classification:
9
9
  def detect_category_openai(self, openai_api_key, categories, email_body):
10
- print("Inside detect_category_openai::")
10
+ logger.log("Inside detect_category_openai::")
11
11
  try:
12
12
  categories_str = ', '.join(categories)
13
13
  message = [{
@@ -15,7 +15,7 @@ class Email_Classification:
15
15
  "content": f"Classify the mail into one of the following categories: {categories_str} and Others. Based on the email content: {email_body}, provide ONLY the category in JSON format as {{\"category\": \"category\"}}."
16
16
  }]
17
17
 
18
- print(f"Final GPT message for detecting category::: {message}")
18
+ logger.log(f"Final GPT message for detecting category::: {message}")
19
19
  client = OpenAI(api_key=openai_api_key)
20
20
  result = client.chat.completions.create(
21
21
  model="gpt-4o-mini",
@@ -27,14 +27,14 @@ class Email_Classification:
27
27
  presence_penalty=0,
28
28
  )
29
29
  category = json.loads(result.choices[0].message.content.replace("\n```", "").replace("```", "").replace("json","").replace("JSON","").replace("csv","").replace("CSV",""))['category']
30
- print(f"category:: {category}")
30
+ logger.log(f"category:: {category}")
31
31
  return {"status": "Success", "message": category}
32
32
  except Exception as e:
33
- print(f"Error detecting category with OpenAI: {str(e)}")
33
+ logger.log(f"Error detecting category with OpenAI: {str(e)}")
34
34
  return {"success": "Failed", "message": f"Error detecting category with OpenAI: {str(e)}"}
35
35
 
36
36
  def detect_category_gemini(self, gemini_api_key, categories, email_body, detect_email_category=True, signature=None):
37
- print("Inside detect_category_gemini::")
37
+ logger.log("Inside detect_category_gemini::")
38
38
  try:
39
39
  categories_str = ', '.join(categories)
40
40
  if detect_email_category:
@@ -48,7 +48,7 @@ class Email_Classification:
48
48
  "content": f"Create a reply for the email received from a customer. Include the email signature as {signature}\nDo not include any instruction as the output will be directly in a program."
49
49
  }]
50
50
 
51
- print(f"Final Gemini AI message for detecting category::: {message}")
51
+ logger.log(f"Final Gemini AI message for detecting category::: {message}")
52
52
  message_list = str(message)
53
53
 
54
54
  generation_config = {
@@ -62,8 +62,8 @@ class Email_Classification:
62
62
  model = genai.GenerativeModel('gemini-1.0-pro')
63
63
  response = model.generate_content(message_list)
64
64
 
65
- print(f"Input Question ::: {email_body}\ngemini-1.0-pro Response::: {response} {type(response)}")
66
- print(f"\n\nResponse GeminiAI endpoint::::: {response} \n{type(response)}", "0")
65
+ logger.log(f"Input Question ::: {email_body}\ngemini-1.0-pro Response::: {response} {type(response)}")
66
+ logger.log(f"\n\nResponse GeminiAI endpoint::::: {response} \n{type(response)}", "0")
67
67
 
68
68
  final_result = ""
69
69
  for part in response:
@@ -74,23 +74,23 @@ class Email_Classification:
74
74
  if final_result.startswith("{{") and final_result.endswith("}}"):
75
75
  final_result = final_result[1:-1]
76
76
  final_result = json.loads(final_result)
77
- print(f"finalResult::: {final_result}")
77
+ logger.log(f"finalResult::: {final_result}")
78
78
  except json.JSONDecodeError:
79
- print(f"Exception : Invalid JSON Response GEMINI 1.5: {final_result} {type(final_result)}")
79
+ logger.log(f"Exception : Invalid JSON Response GEMINI 1.5: {final_result} {type(final_result)}")
80
80
 
81
81
  if detect_email_category:
82
82
  category = final_result.get('category', 'Others')
83
83
  return {"status": "Success", "message": category}
84
84
  else:
85
- print(f"finalResult::: {final_result}")
85
+ logger.log(f"finalResult::: {final_result}")
86
86
  return {"status": "Success", "message": final_result}
87
87
 
88
88
  except Exception as e:
89
- print(f"Error with Gemini AI detection/generation: {str(e)}")
89
+ logger.log(f"Error with Gemini AI detection/generation: {str(e)}")
90
90
  return {"success": "Failed", "message": f"Error with Gemini AI detection/generation: {str(e)}"}
91
91
 
92
92
  def detect_category_local(self, openai_api_key, categories, email_body, detect_email_category=True, signature=None, local_ai_url=None):
93
- print("Inside detect_category_local::")
93
+ logger.log("Inside detect_category_local::")
94
94
  try:
95
95
  categories_str = ', '.join(categories)
96
96
  if detect_email_category:
@@ -104,7 +104,7 @@ class Email_Classification:
104
104
  "content": f"Create a reply for the email received from a customer. Include the email signature as {signature}\nDo not include any instruction as the output will be directly in a program."
105
105
  }]
106
106
 
107
- print(f"Final Local AI message for detecting category::: {message}")
107
+ logger.log(f"Final Local AI message for detecting category::: {message}")
108
108
  openai.api_key = openai_api_key
109
109
  client = OpenAI(base_url=local_ai_url, api_key="lm-studio")
110
110
  completion = client.chat.completions.create(
@@ -116,7 +116,7 @@ class Email_Classification:
116
116
  )
117
117
 
118
118
  final_result = str(completion.choices[0].message.content)
119
- print(f"\n\nInput Question ::: {email_body}\nLocalAI endpoint finalResult ::::: {final_result} \n{type(final_result)}", "0")
119
+ logger.log(f"\n\nInput Question ::: {email_body}\nLocalAI endpoint finalResult ::::: {final_result} \n{type(final_result)}", "0")
120
120
 
121
121
  if detect_email_category:
122
122
  try:
@@ -125,21 +125,21 @@ class Email_Classification:
125
125
  if json_start != -1 and json_end != -1:
126
126
  json_str = final_result[json_start:json_end]
127
127
  final_result = json.loads(json_str)
128
- print(f"finalResult::: {final_result}")
128
+ logger.log(f"finalResult::: {final_result}")
129
129
  category = final_result.get('category', 'Others')
130
- print(f"category::1037 {category}")
130
+ logger.log(f"category::1037 {category}")
131
131
  return {"status": "Success", "message": category}
132
132
  else:
133
133
  raise ValueError("No valid JSON object found in the response")
134
134
  except json.JSONDecodeError as e:
135
- print(f"JSON decode error: {e}")
135
+ logger.log(f"JSON decode error: {e}")
136
136
  raise
137
137
  else:
138
- print(f"finalResult:1040 {final_result}")
138
+ logger.log(f"finalResult:1040 {final_result}")
139
139
  return {"status": "Success", "message": final_result}
140
140
 
141
141
  except Exception as e:
142
- print(f"Error with LocalAI detection/generation: {str(e)}")
142
+ logger.log(f"Error with LocalAI detection/generation: {str(e)}")
143
143
  return {"success": "Failed", "message": f"Error with LocalAI detection/generation: {str(e)}"}
144
144
 
145
145
  def detect_category(self, data):
@@ -180,9 +180,9 @@ class Email_Classification:
180
180
  else:
181
181
  return {"status": "Failed", "message": f"Invalid model_type: {model_type}"}
182
182
 
183
- print(f"Detect_Category response: {response}")
183
+ logger.log(f"Detect_Category response: {response}")
184
184
  return response
185
185
 
186
186
  except Exception as e:
187
- print(f"Error in Detect_Category: {str(e)}")
187
+ logger.log(f"Error in Detect_Category: {str(e)}")
188
188
  return e
@@ -8,7 +8,7 @@ from flask import Flask,request
8
8
  class Email_DocumentUploader:
9
9
  def upload_document(self, upload_config, file_data):
10
10
  # try:
11
- print("inside function" )
11
+ logger.log("inside function" )
12
12
  # Create temp directory if needed
13
13
  temp_dir = "temp"
14
14
  if not os.path.exists(temp_dir):
@@ -16,7 +16,7 @@ class Email_DocumentUploader:
16
16
 
17
17
  # Save file temporarily
18
18
  file_path = os.path.join(temp_dir, file_data['filename'])
19
- print(f"file_path:: {file_path}")
19
+ logger.log(f"file_path:: {file_path}")
20
20
  with open(file_path, 'wb') as f:
21
21
  f.write(file_data['content'])
22
22
 
@@ -30,7 +30,7 @@ class Email_DocumentUploader:
30
30
  "FILE_TYPE": "file_type",
31
31
  "APP_ID": "app_id"
32
32
  }
33
- print(f"param_fields:: {param_fields}")
33
+ logger.log(f"param_fields:: {param_fields}")
34
34
 
35
35
  for api_key, config_key in param_fields.items():
36
36
  if config_key in upload_config and upload_config[config_key]:
@@ -46,7 +46,7 @@ class Email_DocumentUploader:
46
46
  files=files,
47
47
  data=params
48
48
  )
49
- print("file read")
49
+ logger.log("file read")
50
50
 
51
51
  if response.status_code == 200:
52
52
  result = json.loads(response.text)
@@ -56,7 +56,7 @@ class Email_DocumentUploader:
56
56
  return str(response.status_code), f"Upload failed: {response.text}"
57
57
 
58
58
  def email_document_upload(self, file, parameters_details):
59
- print(f"file ::: {file}")
59
+ logger.log(f"file ::: {file}")
60
60
  if not file:
61
61
  return "file not found"
62
62
 
@@ -81,5 +81,5 @@ class Email_DocumentUploader:
81
81
 
82
82
  response_status, restAPI_Result = self.upload_document(upload_config, file_data)
83
83
 
84
- print(f"Upload_Document response result: {restAPI_Result}")
84
+ logger.log(f"Upload_Document response result: {restAPI_Result}")
85
85
  return response_status, restAPI_Result
@@ -27,22 +27,22 @@ class Email_Draft:
27
27
  message.set_payload(f"{response_content}\n\n{mail_details}\n\n{email_details['body']}")
28
28
 
29
29
  utf8_message = str(message).encode("utf-8")
30
- # print(f"utf8_message:: {utf8_message}")
30
+ # logger.log(f"utf8_message:: {utf8_message}")
31
31
  imap_ssl.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), utf8_message)
32
32
 
33
33
  return True, utf8_message.decode("utf-8")
34
34
 
35
35
  except Exception as e:
36
- print(f"Error creating draft: {str(e)}")
36
+ logger.log(f"Error creating draft: {str(e)}")
37
37
 
38
38
  def draft_email_response(self, email_details):
39
39
  try:
40
- print("Creating draft email with the following details:")
41
- print(f"From: {email_details.get('from')}")
42
- print(f"To: {email_details.get('to')}")
43
- print(f"CC: {email_details.get('cc')}")
44
- print(f"Subject: {email_details.get('subject')}")
45
- print(f"Body: {email_details.get('body')}")
40
+ logger.log("Creating draft email with the following details:")
41
+ logger.log(f"From: {email_details.get('from')}")
42
+ logger.log(f"To: {email_details.get('to')}")
43
+ logger.log(f"CC: {email_details.get('cc')}")
44
+ logger.log(f"Subject: {email_details.get('subject')}")
45
+ logger.log(f"Body: {email_details.get('body')}")
46
46
 
47
47
  return "Success", {
48
48
  "from": email_details['from'],
@@ -53,7 +53,7 @@ class Email_Draft:
53
53
  }
54
54
 
55
55
  except Exception as e:
56
- print(f"Error creating draft: {str(e)}")
56
+ logger.log(f"Error creating draft: {str(e)}")
57
57
  return "Failed", None
58
58
 
59
59
  def draft_mail(self, data):
@@ -61,35 +61,35 @@ class Email_Draft:
61
61
 
62
62
  if "reciever_email_addr" in data and data["reciever_email_addr"] != None:
63
63
  reciever_email_addr = data["reciever_email_addr"]
64
- print(f"\nInside reciever_email_addr value:::\t{reciever_email_addr} \t{type(reciever_email_addr)}","0")
64
+ logger.log(f"\nInside reciever_email_addr value:::\t{reciever_email_addr} \t{type(reciever_email_addr)}","0")
65
65
 
66
66
  if "receiver_email_pwd" in data and data["receiver_email_pwd"] != None:
67
67
  receiver_email_pwd = data["receiver_email_pwd"]
68
- print(f"\nInside receiver_email_pwd value:::\t{receiver_email_pwd} \t{type(receiver_email_pwd)}","0")
68
+ logger.log(f"\nInside receiver_email_pwd value:::\t{receiver_email_pwd} \t{type(receiver_email_pwd)}","0")
69
69
 
70
70
  if "host_name" in data and data["host_name"] != None:
71
71
  host_name = data["host_name"]
72
- print(f"\nInside host_name value:::\t{host_name} \t{type(host_name)}","0")
72
+ logger.log(f"\nInside host_name value:::\t{host_name} \t{type(host_name)}","0")
73
73
 
74
74
  if "sender_email_addr" in data and data["sender_email_addr"] != None:
75
75
  sender_email_addr = data["sender_email_addr"]
76
- print(f"\nInside sender_email_addr value:::\t{sender_email_addr} \t{type(sender_email_addr)}","0")
76
+ logger.log(f"\nInside sender_email_addr value:::\t{sender_email_addr} \t{type(sender_email_addr)}","0")
77
77
 
78
78
  if "cc_email_addr" in data and data["cc_email_addr"] != None:
79
79
  cc_email_addr = data["cc_email_addr"]
80
- print(f"\nInside cc_email_addr value:::\t{cc_email_addr} \t{type(cc_email_addr)}","0")
80
+ logger.log(f"\nInside cc_email_addr value:::\t{cc_email_addr} \t{type(cc_email_addr)}","0")
81
81
 
82
82
  if "subject" in data and data["subject"] != None:
83
83
  subject = data["subject"]
84
- print(f"\nInside subject value:::\t{subject} \t{type(subject)}","0")
84
+ logger.log(f"\nInside subject value:::\t{subject} \t{type(subject)}","0")
85
85
 
86
86
  if "email_body" in data and data["email_body"] != None:
87
87
  email_body = data["email_body"]
88
- print(f"\nInside email_body value:::\t{email_body} \t{type(email_body)}","0")
88
+ logger.log(f"\nInside email_body value:::\t{email_body} \t{type(email_body)}","0")
89
89
 
90
90
  if "signature" in data and data["signature"] != None:
91
91
  signature = data["signature"]
92
- print(f"\nInside signature value:::\t{signature} \t{type(signature)}","0")
92
+ logger.log(f"\nInside signature value:::\t{signature} \t{type(signature)}","0")
93
93
 
94
94
 
95
95
  email_config = {
@@ -97,7 +97,7 @@ class Email_Draft:
97
97
  "password": data["receiver_email_pwd"],
98
98
  "host": data["host_name"]
99
99
  }
100
- print(f"data::{data}")
100
+ logger.log(f"data::{data}")
101
101
  email_details = {
102
102
  "from": data["sender_email_addr"],
103
103
  "to":data["reciever_email_addr"],
@@ -110,8 +110,8 @@ class Email_Draft:
110
110
  success, draft_message = self.draft_email_response(email_details)
111
111
 
112
112
  if success == "Success":
113
- print(f"draft_message {draft_message}")
113
+ logger.log(f"draft_message {draft_message}")
114
114
  return draft_message
115
115
 
116
116
  except Exception as e:
117
- print(f"Error in Draft_Save: {str(e)}")
117
+ logger.log(f"Error in Draft_Save: {str(e)}")
@@ -18,10 +18,10 @@ from .Email_DocumentUploader import Email_DocumentUploader
18
18
  class Email_Read:
19
19
  def read_email(self, email_config):
20
20
  try:
21
- print("inside read_email")
21
+ logger.log("inside read_email")
22
22
  mail = imaplib.IMAP4_SSL(email_config['host'], email_config['port'])
23
23
  mail.login(email_config['email'], email_config['password'])
24
- print("login successfully")
24
+ logger.log("login successfully")
25
25
  mail.select('inbox')
26
26
 
27
27
  while True:
@@ -32,8 +32,8 @@ class Email_Read:
32
32
  email_ids = email_ids[0].split()
33
33
 
34
34
  if not email_ids:
35
- print("Email not found, going to check new mail")
36
- print("Email not found,\ngoing to check new mail \n")
35
+ logger.log("Email not found, going to check new mail")
36
+ logger.log("Email not found,\ngoing to check new mail \n")
37
37
  else:
38
38
 
39
39
  for email_id in email_ids:
@@ -67,10 +67,10 @@ class Email_Read:
67
67
  "body": email_body
68
68
  }
69
69
  emails.append(email_data)
70
- print(f"emails:: {emails}")
70
+ logger.log(f"emails:: {emails}")
71
71
  call_save_transaction = Save_Transaction()
72
72
  save_transaction_response = call_save_transaction.email_save_transaction(email_data)
73
- print(f"save_transaction_response:: {save_transaction_response}")
73
+ logger.log(f"save_transaction_response:: {save_transaction_response}")
74
74
  time.sleep(10)
75
75
 
76
76
  except Exception as e:
@@ -80,12 +80,12 @@ class Email_Read:
80
80
  mail.close()
81
81
  mail.logout()
82
82
  except Exception as close_error:
83
- print(f"Error during mail close/logout: {str(close_error)}")
83
+ logger.log(f"Error during mail close/logout: {str(close_error)}")
84
84
 
85
85
  def read_email_automation(self, email_config):
86
86
  # try:
87
- print(f"inside read_email_automation")
88
- # print(f"email_config ::: {email_config}")
87
+ logger.log(f"inside read_email_automation")
88
+ # logger.log(f"email_config ::: {email_config}")
89
89
  LABEL = "Unprocessed_Email"
90
90
  file_JsonArray = []
91
91
  templateName = "ai_email_automation.json"
@@ -99,7 +99,7 @@ class Email_Read:
99
99
 
100
100
  mail = imaplib.IMAP4_SSL(host, port)
101
101
  mail.login(reciever_email_addr, receiver_email_pwd)
102
- print("login successfully")
102
+ logger.log("login successfully")
103
103
  mail.select('inbox')
104
104
 
105
105
  file_JsonArray, categories = self.read_JSON_File(templateName)
@@ -112,8 +112,8 @@ class Email_Read:
112
112
  email_ids = email_ids[0].split()
113
113
 
114
114
  if not email_ids:
115
- print("Email not found, going to check new mail")
116
- print("Email not found,\ngoing to check new mail \n")
115
+ logger.log("Email not found, going to check new mail")
116
+ logger.log("Email not found,\ngoing to check new mail \n")
117
117
  else:
118
118
 
119
119
  for email_id in email_ids:
@@ -140,8 +140,8 @@ class Email_Read:
140
140
  email_body = msg.get_payload(decode=True).decode('utf-8', errors='replace')
141
141
 
142
142
  openai_Process_Input = email_body
143
- print(f"\nEmail Subject::: {subject}")
144
- print(f"\nEmail body::: {openai_Process_Input}")
143
+ logger.log(f"\nEmail Subject::: {subject}")
144
+ logger.log(f"\nEmail body::: {openai_Process_Input}")
145
145
 
146
146
  openai_api_key = email_config.get('openai_api_key', '')
147
147
  geminiAI_APIKey = email_config.get('gemini_api_key', '')
@@ -158,21 +158,21 @@ class Email_Read:
158
158
  "signature" : signature,
159
159
  "local_ai_url" : localAIURL,
160
160
  }
161
- # print(f"\nemail_cat_data ::: {email_cat_data}")
161
+ # logger.log(f"\nemail_cat_data ::: {email_cat_data}")
162
162
  email_classification = Email_Classification()
163
163
  emailCategory = email_classification.detect_category(email_cat_data)
164
164
  emailCategory = emailCategory['message']
165
- print(f"\nDetected Email category ::: {emailCategory}")
165
+ logger.log(f"\nDetected Email category ::: {emailCategory}")
166
166
 
167
167
  if emailCategory == 'Others':
168
- print(f"Marking email as UNREAD. ")
168
+ logger.log(f"Marking email as UNREAD. ")
169
169
  mail.store(email_id, '-FLAGS', '\\Seen')
170
170
 
171
171
  mail.create(LABEL)
172
172
  mail.copy(email_id, LABEL)
173
173
  mail.store(email_id, '+FLAGS', '\\Deleted') # Mark for deletion
174
174
  mail.expunge()
175
- print(f"Mail removed from inbox and added to '{LABEL}' label.")
175
+ logger.log(f"Mail removed from inbox and added to '{LABEL}' label.")
176
176
 
177
177
  elif emailCategory == "Product Enquiry":
178
178
 
@@ -183,42 +183,42 @@ class Email_Read:
183
183
  emailreplyassistant = EmailReplyAssistant()
184
184
  openai_Response = emailreplyassistant.Reply_Email_Ai_Assistant(openai_api_key, parameters["Assistant_Id"], openai_Process_Input, subject)
185
185
 
186
- print(f"Process openai_Response ::: {openai_Response['message']}\n")
186
+ logger.log(f"Process openai_Response ::: {openai_Response['message']}\n")
187
187
  email_details = {"sender":sender_email_addr, "cc":cc_email_addr, "subject":subject, "body": email_body}
188
188
 
189
189
  email_draft = Email_Draft()
190
190
  status, response = email_draft.draft_email(email_config, email_details, openai_Response['message'])
191
- print(f"status ::: {status}")
191
+ logger.log(f"status ::: {status}")
192
192
  else :
193
193
  message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
194
194
  raise ValueError(message)
195
195
  elif Model_Name == "LocalAI":
196
- print("localAI")
196
+ logger.log("localAI")
197
197
  Detect_Email_category = False
198
198
  LocalAI_Response = emailCategory
199
- print(f"Process LocalAI_Response ::: {LocalAI_Response}\n")
199
+ logger.log(f"Process LocalAI_Response ::: {LocalAI_Response}\n")
200
200
  email_details = {"sender":sender_email_addr, "cc":cc_email_addr, "subject":subject, "body": email_body}
201
201
 
202
202
  email_draft = Email_Draft()
203
203
  status, response = email_draft.draft_email(email_config, email_details, LocalAI_Response)
204
- print(f"status ::: {status}")
204
+ logger.log(f"status ::: {status}")
205
205
  elif Model_Name == "GeminiAI":
206
- print("GeminiAI")
206
+ logger.log("GeminiAI")
207
207
  Detect_Email_category = False
208
208
  GeminiAI_Response = emailCategory
209
- print(f"Process GeminiAI_Response ::: {GeminiAI_Response}\n")
209
+ logger.log(f"Process GeminiAI_Response ::: {GeminiAI_Response}\n")
210
210
  email_details = {"sender":sender_email_addr, "cc":cc_email_addr, "subject":subject, "body": email_body}
211
211
 
212
212
  email_draft = Email_Draft()
213
213
  status, response = email_draft.draft_email(email_config, email_details, GeminiAI_Response)
214
- print(f"status ::: {status}")
214
+ logger.log(f"status ::: {status}")
215
215
  else:
216
216
  raise ValueError(f"Invalid Model Name provided : '{Model_Name}'")
217
217
 
218
218
  elif emailCategory == "Purchase Order":
219
219
  responseMethod, parameters = self.get_JsonArray_values(emailCategory, file_JsonArray)
220
- print(f"responseMethod ::: {responseMethod}")
221
- print(f"parameters ::: {parameters}")
220
+ logger.log(f"responseMethod ::: {responseMethod}")
221
+ logger.log(f"parameters ::: {parameters}")
222
222
  if responseMethod == "Upload_Document" :
223
223
 
224
224
  if len(fileName) != 0 :
@@ -226,18 +226,18 @@ class Email_Read:
226
226
  email_upload_document = Email_DocumentUploader()
227
227
  with open(f"temp/{fileName}", "rb") as file:
228
228
  response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
229
- print(f"email_upload_document_response ::: {restAPI_Result}")
229
+ logger.log(f"email_upload_document_response ::: {restAPI_Result}")
230
230
  else:
231
231
 
232
232
  new_fileName = self.create_file_from_emailBody(email_body, sender_email_addr, parameters)
233
233
  with open(f"temp/{new_fileName}", "rb") as file:
234
234
  response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
235
- print(f"email_upload_document_response ::: {restAPI_Result}")
235
+ logger.log(f"email_upload_document_response ::: {restAPI_Result}")
236
236
 
237
237
  if response_status == "200" :
238
- print(f"Attachment uploaded sucessfully against Document id: '{restAPI_Result}'.")
238
+ logger.log(f"Attachment uploaded sucessfully against Document id: '{restAPI_Result}'.")
239
239
  else:
240
- print(restAPI_Result)
240
+ logger.log(restAPI_Result)
241
241
 
242
242
  else :
243
243
  message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
@@ -254,7 +254,7 @@ class Email_Read:
254
254
  # mail.close()
255
255
  # mail.logout()
256
256
  # except Exception as close_error:
257
- # print(f"Error during mail close/logout: {str(close_error)}")
257
+ # logger.log(f"Error during mail close/logout: {str(close_error)}")
258
258
  # return {"status": "Failed", "message": f"Error reading emails: {str(close_error)}"}
259
259
 
260
260
  def save_attachment(self, part, download_dir):
@@ -269,7 +269,7 @@ class Email_Read:
269
269
  with open(file_path, 'wb') as f:
270
270
  f.write(part.get_payload(decode=True))
271
271
 
272
- print(f"Attachment saved: {file_path}")
272
+ logger.log(f"Attachment saved: {file_path}")
273
273
  return file_path
274
274
  except Exception as e:
275
275
  return {"success": "Failed", "message": f"Error saving attachment: {str(e)}"}
@@ -288,10 +288,10 @@ class Email_Read:
288
288
  if not all([reciever_email_addr, receiver_email_pwd, host, port]):
289
289
  raise ValueError("Missing required email configuration fields.")
290
290
 
291
- print(f"\nReceiver Email Address: {reciever_email_addr}\t{type(reciever_email_addr)}", "0")
292
- print(f"\nReceiver Email Password: {receiver_email_pwd}\t{type(receiver_email_pwd)}", "0")
293
- print(f"\nHost: {host}\t{type(host)}", "0")
294
- print(f"\nPort: {port}\t{type(port)}", "0")
291
+ logger.log(f"\nReceiver Email Address: {reciever_email_addr}\t{type(reciever_email_addr)}", "0")
292
+ logger.log(f"\nReceiver Email Password: {receiver_email_pwd}\t{type(receiver_email_pwd)}", "0")
293
+ logger.log(f"\nHost: {host}\t{type(host)}", "0")
294
+ logger.log(f"\nPort: {port}\t{type(port)}", "0")
295
295
 
296
296
  email_config = {
297
297
  'email': reciever_email_addr,
@@ -303,11 +303,11 @@ class Email_Read:
303
303
  'local_ai_url': localAIURL
304
304
  }
305
305
 
306
- emails = self.read_email(email_config)
307
- print(f"Read_Email response: {emails}")
306
+ emails = self.read_email_automation(email_config)
307
+ logger.log(f"Read_Email response: {emails}")
308
308
 
309
309
  except Exception as e:
310
- print(f"Error in Read_Email: {str(e)}")
310
+ logger.log(f"Error in Read_Email: {str(e)}")
311
311
 
312
312
  def download_attachment(self, msg):
313
313
  filepath = ""
@@ -328,9 +328,9 @@ class Email_Read:
328
328
  filepath = os.path.join(ATTACHMENT_SAVE_PATH, filename)
329
329
  with open(filepath, 'wb') as f:
330
330
  f.write(part.get_payload(decode=True))
331
- print(f"\nAttachment saved: '{filepath}'")
331
+ logger.log(f"\nAttachment saved: '{filepath}'")
332
332
  else:
333
- print("\nNo Attachment found.")
333
+ logger.log("\nNo Attachment found.")
334
334
  return filename
335
335
 
336
336
  def read_JSON_File(self, json_fileName):
@@ -355,7 +355,7 @@ class Email_Read:
355
355
  except Exception as e:
356
356
  msg = f"'{json_fileName}' file is empty. Please provide JSON parameters in the filename."
357
357
  trace = traceback.format_exc()
358
- print(f"Exception in writeJsonFile: {msg} \n {trace} \n DataType ::: {type(msg)}")
358
+ logger.log(f"Exception in writeJsonFile: {msg} \n {trace} \n DataType ::: {type(msg)}")
359
359
  raise Exception(msg)
360
360
 
361
361
  def get_JsonArray_values(self, category, jsonArray):
@@ -386,7 +386,7 @@ class Email_Read:
386
386
  pdf.set_font("Arial", size=12)
387
387
  pdf.multi_cell(0, 10, text)
388
388
  pdf.output(filePath)
389
- print(f"New PDF file created from email body and stored in '{filePath}'")
389
+ logger.log(f"New PDF file created from email body and stored in '{filePath}'")
390
390
 
391
391
  elif parameters["FILE_TYPE"] == "txt":
392
392
  fileName = fileName + ".txt"
@@ -394,7 +394,7 @@ class Email_Read:
394
394
 
395
395
  with open(filePath, "w") as file:
396
396
  file.write(text)
397
- print(f"New TXT file created from email body and stored in '{filePath}'")
397
+ logger.log(f"New TXT file created from email body and stored in '{filePath}'")
398
398
  else:
399
399
  message = f"Invalid File Type received. "
400
400
  self.send_response(200)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: AIEmailAutomationUtility
3
- Version: 0.0.13
3
+ Version: 0.0.15
4
4
  Summary: Create 2 different methods in read_email for different client
5
5
  Author: Proteus Technology PVT. LTD.
6
6
  Author-email: <apps@baseinformation.com>
@@ -0,0 +1,14 @@
1
+ AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=AK2I1j2wa6NvR9ysKgtQsm-wkaeKQycQdzREXR0Ptb8,3886
2
+ AIEmailAutomationUtility/Email_Classification.py,sha256=eL52Td50zo7V0QTIqjN4Khhg-5HKvf2RUITIcKz5yZ0,9343
3
+ AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=ImTmMz_JeU6Xynt9kyu7lFv7vqrxzqAtBF-A7014fYc,3055
4
+ AIEmailAutomationUtility/Email_Draft.py,sha256=BfseewnnlwNl1moodq3kZiUPXDUE9a_nQjuFQsUp3fY,5244
5
+ AIEmailAutomationUtility/Email_Read.py,sha256=RvhT_PU61ZpKnbnY6lkv_JEbnSjdbgSk0B5cmx2XECw,20803
6
+ AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
7
+ AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
8
+ AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
9
+ AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
10
+ AIEmailAutomationUtility-0.0.15.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
11
+ AIEmailAutomationUtility-0.0.15.dist-info/METADATA,sha256=cMEIkqx-eae2E8plU6ixpdeJoh8BCYmPRwvQNlp58Ek,623
12
+ AIEmailAutomationUtility-0.0.15.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
+ AIEmailAutomationUtility-0.0.15.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
14
+ AIEmailAutomationUtility-0.0.15.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=qW4Rmh7NwoxktTUtqGB-de_07VcqzTNtTPg1sWsi9Sg,3888
2
- AIEmailAutomationUtility/Email_Classification.py,sha256=lJApk8X2xiAt6xTNBtTCewh2aJpyGF_wfPwrd3lfW4s,9233
3
- AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=zXF6PNkRjkgbe3daxbZ_XS8M1KpKKNWcmWzu-BUhxJM,3025
4
- AIEmailAutomationUtility/Email_Draft.py,sha256=RJSoZ4tyjypjOU415YcGJYJ2Nx9uTKEPA1mCQxNH57E,5144
5
- AIEmailAutomationUtility/Email_Read.py,sha256=-ewBgnTqM0j_OzAwGz02OOW77sEVmDGxX-19PFxSemE,20567
6
- AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
7
- AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
8
- AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
9
- AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
10
- AIEmailAutomationUtility-0.0.13.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
11
- AIEmailAutomationUtility-0.0.13.dist-info/METADATA,sha256=0kh8kQD8pIXEywLMl0RLvRkKBDycZEWDLt4_kz2ERm8,623
12
- AIEmailAutomationUtility-0.0.13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
- AIEmailAutomationUtility-0.0.13.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
14
- AIEmailAutomationUtility-0.0.13.dist-info/RECORD,,