Spaces:
Running
Running
Update get_gmail_data.py
Browse files- get_gmail_data.py +7 -4
get_gmail_data.py
CHANGED
@@ -159,9 +159,9 @@ class GmailDataExtractor:
|
|
159 |
|
160 |
if data:
|
161 |
# Save only the first 10 characters of the attachment data
|
162 |
-
return subject,body ,
|
163 |
|
164 |
-
return subject, body,
|
165 |
|
166 |
def extract_text_and_links(html_content: str) -> tuple:
|
167 |
"""
|
@@ -200,7 +200,7 @@ class GmailDataExtractor:
|
|
200 |
|
201 |
Returns:
|
202 |
dict: A dictionary containing the extracted messages with their subjects, bodies, links, and attachment statuses.
|
203 |
-
format:{"results":[{"subjec":"test subject" , "body":"it would be text" , "attachment_data":{"filename":
|
204 |
|
205 |
"""
|
206 |
messages = self.__fetch_messages()
|
@@ -213,6 +213,9 @@ class GmailDataExtractor:
|
|
213 |
body = body if body is not None else ""
|
214 |
attachment_data = attachment_data if attachment_data is not None else {}
|
215 |
|
216 |
-
|
|
|
|
|
|
|
217 |
|
218 |
return {"results": results}
|
|
|
159 |
|
160 |
if data:
|
161 |
# Save only the first 10 characters of the attachment data
|
162 |
+
return subject,body ,{"filename":filename , "base64URLData":data}
|
163 |
|
164 |
+
return subject, body,None
|
165 |
|
166 |
def extract_text_and_links(html_content: str) -> tuple:
|
167 |
"""
|
|
|
200 |
|
201 |
Returns:
|
202 |
dict: A dictionary containing the extracted messages with their subjects, bodies, links, and attachment statuses.
|
203 |
+
format:{"results":[{"subjec":"test subject" , "body":"it would be text" , "attachment_data":{"filename":filename,"base64URLData":data}},{second message with same content of subject , body , attachment_data}]}
|
204 |
|
205 |
"""
|
206 |
messages = self.__fetch_messages()
|
|
|
213 |
body = body if body is not None else ""
|
214 |
attachment_data = attachment_data if attachment_data is not None else {}
|
215 |
|
216 |
+
if attachment_data: # Check if attachment_data is present
|
217 |
+
results.append({"attachment_data": attachment_data})
|
218 |
+
elif body: # If attachment_data is absent, append body only if it's not empty
|
219 |
+
results.append({"body": body})
|
220 |
|
221 |
return {"results": results}
|