Omkar008 commited on
Commit
8d0af99
1 Parent(s): 9c2f75f

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +18 -12
test.py CHANGED
@@ -71,7 +71,8 @@ async def test_google(code:str):
71
  messages = []
72
  # user_query = f"subject:((receipt {brand_name}) OR (receipts {brand_name}) OR (reçu {brand_name}) OR (reçus {brand_name}) OR (Quittung {brand_name}) OR (Quittungen {brand_name}) OR (aankoopbon {brand_name}) OR (aankoopbonnen {brand_name}) OR (recibo {brand_name}) OR (recibos {brand_name}) OR (ricevuta {brand_name}) OR (ricevute {brand_name}) OR (ontvangstbewijs {brand_name}) OR (ontvangstbewijzen {brand_name})) has:attachment"
73
  # user_query = f"{brand_name} label:^smartlabel_receipt"
74
- user_query = """("invoice" OR (("tracking" OR "track") AND ("delivery" OR "package"))) OR (subject:order OR subject:receipt OR subject:receipts OR subject:invoice OR subject:invoice)"""
 
75
  while True:
76
  # Construct Gmail API request with pageToken
77
 
@@ -116,17 +117,22 @@ async def test_google(code:str):
116
  message_url = f"https://www.googleapis.com/gmail/v1/users/me/messages/{message_id}"
117
  message_response = requests.get(message_url, headers={"Authorization": f"Bearer {access_token}"})
118
  message_data = message_response.json()
119
-
120
-
121
- if "payload" in message_data:
122
- payload = message_data["payload"]
123
- if "body" in payload and "data" in payload["body"]:
124
- body_data = payload["body"]["data"]
125
- body_content = base64.urlsafe_b64decode(body_data.encode("UTF-8")).decode("UTF-8")
126
- print("Body Content:")
127
- print(body_content)
128
- print()
129
- print()
 
 
 
 
 
130
 
131
  # Check for parts in the message payload
132
  if "payload" in message_data and "parts" in message_data["payload"]:
 
71
  messages = []
72
  # user_query = f"subject:((receipt {brand_name}) OR (receipts {brand_name}) OR (reçu {brand_name}) OR (reçus {brand_name}) OR (Quittung {brand_name}) OR (Quittungen {brand_name}) OR (aankoopbon {brand_name}) OR (aankoopbonnen {brand_name}) OR (recibo {brand_name}) OR (recibos {brand_name}) OR (ricevuta {brand_name}) OR (ricevute {brand_name}) OR (ontvangstbewijs {brand_name}) OR (ontvangstbewijzen {brand_name})) has:attachment"
73
  # user_query = f"{brand_name} label:^smartlabel_receipt"
74
+ user_query = f"(label:^smartlabel_receipt OR (subject:your AND subject:order) OR subject:receipts OR subject:receipt OR subject:invoice OR subject:invoice)) AND subject:chanel"
75
+ # user_query = """("invoice" OR (("tracking" OR "track") AND ("delivery" OR "package"))) OR (subject:order OR subject:receipt OR subject:receipts OR subject:invoice OR subject:invoice)"""
76
  while True:
77
  # Construct Gmail API request with pageToken
78
 
 
117
  message_url = f"https://www.googleapis.com/gmail/v1/users/me/messages/{message_id}"
118
  message_response = requests.get(message_url, headers={"Authorization": f"Bearer {access_token}"})
119
  message_data = message_response.json()
120
+ print(message_data)
121
+
122
+ if 'payload' in message and 'headers' in message['payload']:
123
+ headers = message['payload']['headers']
124
+ for header in headers:
125
+ if header['name'] == 'Subject':
126
+ subject = header['value']
127
+
128
+ if 'parts' in message['payload']:
129
+ parts = message['payload']['parts']
130
+ for part in parts:
131
+ if part['mimeType'] == 'text/plain':
132
+ body_data = part['body']['data']
133
+ body = base64.urlsafe_b64decode(body_data).decode()
134
+ print("Subject:", subject)
135
+ print("Body:", body)
136
 
137
  # Check for parts in the message payload
138
  if "payload" in message_data and "parts" in message_data["payload"]: