Omkar008 commited on
Commit
f562fef
1 Parent(s): 0441232

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +35 -8
test.py CHANGED
@@ -61,14 +61,41 @@ async def auth_google(request: Request):
61
  # print(response.json())
62
  # print(access_token_new)
63
  user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
64
- # user_query = data.get("user_query")
65
- query = "subject:receipt OR subject:receipts has:attachment"
66
- gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={query}"
67
- gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token_new}"})
68
- messages = gmail_response.json().get("messages", [])
69
- print(messages)
70
- print("Printing gmail response")
71
- print(gmail_response.json())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  # Fetch attachments from the first message
73
  attachments = []
74
  attachment_no = 0
 
61
  # print(response.json())
62
  # print(access_token_new)
63
  user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
64
+ # user_query = data.get("user_query")
65
+ page_token = None
66
+ messages = []
67
+ jobs_query = "subject:IOS developer has:attachment"
68
+
69
+ while True:
70
+ # Construct Gmail API request with pageToken
71
+ gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}"
72
+ if page_token:
73
+ gmail_url += f"&pageToken={page_token}"
74
+
75
+ gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token_new}"})
76
+ gmail_data = gmail_response.json()
77
+
78
+ # Check if there are messages in the response
79
+ if "messages" in gmail_data:
80
+ messages.extend(gmail_data["messages"])
81
+
82
+ # Check if there are more pages
83
+ if "nextPageToken" in gmail_data:
84
+ page_token = gmail_data["nextPageToken"]
85
+ else:
86
+ break # No more pages, exit the loop
87
+
88
+
89
+ print(len(messages))
90
+
91
+
92
+ # query = "subject:receipt OR subject:receipts has:attachment"
93
+ # gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={query}"
94
+ # gmail_response = requests.get(gmail_url, headers={"Authorization": f"Bearer {access_token_new}"})
95
+ # messages = gmail_response.json().get("messages", [])
96
+ # print(messages)
97
+ # print("Printing gmail response")
98
+ # print(gmail_response.json())
99
  # Fetch attachments from the first message
100
  attachments = []
101
  attachment_no = 0