Omkar008 commited on
Commit
83e4f7b
1 Parent(s): 924753b

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +4 -7
test.py CHANGED
@@ -1,7 +1,6 @@
1
  from fastapi import FastAPI, Depends , Request,WebSocket
2
  from fastapi.security import OAuth2PasswordBearer
3
  import requests
4
- from jose import jwt
5
  import webbrowser
6
  import base64
7
  import logging
@@ -40,7 +39,6 @@ async def login_google():
40
  #Below is the URL to prompt the user to login to his specified gmail account and also give a readonly access to his gmail
41
  oauth_url = f"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={GOOGLE_CLIENT_ID}&redirect_uri={GOOGLE_REDIRECT_URI}&scope=openid%20profile%20email%20https://www.googleapis.com/auth/gmail.readonly&access_type=offline"
42
  oauth_url_hr = f"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={GOOGLE_CLIENT_ID}&redirect_uri={GOOGLE_REDIRECT_URI}&scope=openid%20profile%20email%20https://www.googleapis.com/auth/gmail.readonly&access_type=offline&state=receipts"
43
- webbrowser.open(oauth_url)
44
  return {
45
  "url_hr": oauth_url_hr
46
  }
@@ -50,6 +48,7 @@ async def auth_google(request: Request):
50
 
51
  data = await request.json()
52
  code = data.get("access_token")
 
53
  print("Printing the access token")
54
  print(code)
55
  if not code:
@@ -59,11 +58,11 @@ async def auth_google(request: Request):
59
  user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
60
  page_token = None
61
  messages = []
62
- jobs_query = "subject:receipt OR subject:receipts has:attachment "
63
 
64
  while True:
65
  # Construct Gmail API request with pageToken
66
- gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={jobs_query}"
67
  if page_token:
68
  gmail_url += f"&pageToken={page_token}"
69
 
@@ -274,9 +273,7 @@ async def test_websocket(websocket: WebSocket):
274
  logging.info("Closing connection")
275
  await websocket.close()
276
 
277
- @app.get("/token")
278
- async def get_token(token: str = Depends(oauth2_scheme)):
279
- return jwt.decode(token, GOOGLE_CLIENT_SECRET, algorithms=["HS256"])
280
 
281
 
282
 
 
1
  from fastapi import FastAPI, Depends , Request,WebSocket
2
  from fastapi.security import OAuth2PasswordBearer
3
  import requests
 
4
  import webbrowser
5
  import base64
6
  import logging
 
39
  #Below is the URL to prompt the user to login to his specified gmail account and also give a readonly access to his gmail
40
  oauth_url = f"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={GOOGLE_CLIENT_ID}&redirect_uri={GOOGLE_REDIRECT_URI}&scope=openid%20profile%20email%20https://www.googleapis.com/auth/gmail.readonly&access_type=offline"
41
  oauth_url_hr = f"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={GOOGLE_CLIENT_ID}&redirect_uri={GOOGLE_REDIRECT_URI}&scope=openid%20profile%20email%20https://www.googleapis.com/auth/gmail.readonly&access_type=offline&state=receipts"
 
42
  return {
43
  "url_hr": oauth_url_hr
44
  }
 
48
 
49
  data = await request.json()
50
  code = data.get("access_token")
51
+ brand_name = data.get("brand_name")
52
  print("Printing the access token")
53
  print(code)
54
  if not code:
 
58
  user_info = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers={"Authorization": f"Bearer {access_token_new}"})
59
  page_token = None
60
  messages = []
61
+ user_query = f"subject:((receipt {brand_name}) OR (receipts {brand_name})) has:attachment "
62
 
63
  while True:
64
  # Construct Gmail API request with pageToken
65
+ gmail_url = f"https://www.googleapis.com/gmail/v1/users/me/messages?q={user_query}"
66
  if page_token:
67
  gmail_url += f"&pageToken={page_token}"
68
 
 
273
  logging.info("Closing connection")
274
  await websocket.close()
275
 
276
+
 
 
277
 
278
 
279