CaesarCloudSync commited on
Commit
3c86687
1 Parent(s): d271195

CaesarFinance setup code implemented

Browse files
Files changed (2) hide show
  1. CaesarFinance/caesarfinance.py +35 -6
  2. main.py +0 -18
CaesarFinance/caesarfinance.py CHANGED
@@ -6,8 +6,9 @@ class CaesarFinance:
6
  def __init__(self) -> None:
7
  self.CLIENT_ID = config('CLIENT_ID')
8
  self.CLIENT_SECRET = config('CLIENT_SECRET')
 
9
  def create_access_code(self):
10
- print(f"https://auth.monzo.com/?client_id={self.CLIENT_ID}&redirect_uri=https://palondomus-caesarai.hf.space/caesaraisavecode&response_type=code&state=state_token")
11
  val = input("Have you created the access code? (y), (n)")
12
  if val.lower() == "y":
13
  return True
@@ -16,9 +17,7 @@ class CaesarFinance:
16
  else:
17
  return False
18
 
19
- def fetch_access_code(self):
20
- resp = requests.get("https://palondomus-caesarai.hf.space/caesaraigetcode")
21
- return resp.json()["messagecode"]
22
  def get_access_token(self,code):
23
  form_data = {'grant_type': 'authorization_code','client_id':self.CLIENT_ID,'client_secret':self.CLIENT_SECRET,
24
  "redirect_uri":"https://palondomus-caesarai.hf.space",
@@ -27,6 +26,22 @@ class CaesarFinance:
27
  server = requests.post('https://api.monzo.com/oauth2/token', data=form_data)
28
  output = server.json()["access_token"]
29
  return output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  if __name__ == "__main__":
32
  caesarfinance = CaesarFinance()
@@ -35,8 +50,22 @@ if __name__ == "__main__":
35
  access_code_bool = caesarfinance.create_access_code()
36
 
37
  #code = caesarfinance.fetch_access_code()
38
- #access_token = caesarfinance.get_access_token(code)
39
- #print(access_token)
 
 
 
 
 
 
 
 
 
 
 
40
 
 
 
 
41
 
42
  #caesarfinance.get_access_code()
 
6
  def __init__(self) -> None:
7
  self.CLIENT_ID = config('CLIENT_ID')
8
  self.CLIENT_SECRET = config('CLIENT_SECRET')
9
+ self.access_token = None
10
  def create_access_code(self):
11
+ print(f"https://auth.monzo.com/?client_id={self.CLIENT_ID}&redirect_uri=https://palondomus-caesarai.hf.space&response_type=code&state=state_token")
12
  val = input("Have you created the access code? (y), (n)")
13
  if val.lower() == "y":
14
  return True
 
17
  else:
18
  return False
19
 
20
+
 
 
21
  def get_access_token(self,code):
22
  form_data = {'grant_type': 'authorization_code','client_id':self.CLIENT_ID,'client_secret':self.CLIENT_SECRET,
23
  "redirect_uri":"https://palondomus-caesarai.hf.space",
 
26
  server = requests.post('https://api.monzo.com/oauth2/token', data=form_data)
27
  output = server.json()["access_token"]
28
  return output
29
+ def whoami(self):
30
+ response = requests.get("https://api.monzo.com/ping/whoami",headers={'Authorization': 'Bearer ' + self.access_token})
31
+ return response.json()
32
+ def get_accounts(self):
33
+ response = requests.get("https://api.monzo.com/accounts",headers={'Authorization': 'Bearer ' + self.access_token})
34
+ return response.json()
35
+ def phone_auth(self):
36
+ phone_auth_val = input("Authenticated on phone? (y),(n)")
37
+ if phone_auth_val.lower() == "y":
38
+ return True
39
+ elif phone_auth_val.lower() == "n":
40
+ return False
41
+ else:
42
+ return False
43
+
44
+
45
 
46
  if __name__ == "__main__":
47
  caesarfinance = CaesarFinance()
 
50
  access_code_bool = caesarfinance.create_access_code()
51
 
52
  #code = caesarfinance.fetch_access_code()
53
+ access_token_bool = False
54
+ while access_token_bool == False:
55
+ code = input("Insert access token:")
56
+ if "eyJhb" in code:
57
+ access_token_bool = True
58
+ elif "eyJhb" not in code:
59
+ access_token_bool = False
60
+
61
+ access_token = caesarfinance.get_access_token(code)
62
+ caesarfinance.access_token = access_token
63
+ access_phone_auth = False
64
+ while access_phone_auth == False:
65
+ access_phone_auth = caesarfinance.phone_auth()
66
 
67
+
68
+ accountinfo = caesarfinance.get_accounts()
69
+ print(accountinfo)
70
 
71
  #caesarfinance.get_access_code()
main.py CHANGED
@@ -55,24 +55,6 @@ def caesaraihome():
55
  def caesarailogo():
56
  return FileResponse(f"{CURRENT_DIR}/CaesarAILogo.png")
57
 
58
- #@app.get("/caesaraisavecode")
59
- #def caesaraisavecode(code: Union[str,None]):
60
- # if code != None:
61
- # with open(f"{CURRENT_DIR}/CaesarFinance/current_code.txt","w+") as f:
62
- # f.write(code)
63
- # return {"message":"Temporary fetching code stored."}
64
- # elif code== None:
65
- # return {"message":"code doesn't exist."}
66
- #@app.get("/caesaraigetcode")
67
- #def caesaraigetcode():
68
- # if "current_code.txt" in os.listdir(f"{CURRENT_DIR}/CaesarFinance"):
69
- # f = open(f"{CURRENT_DIR}/CaesarFinance/current_code.txt","r")
70
- # code = f.read()
71
- # f.close()
72
- # os.remove(f"{CURRENT_DIR}/CaesarFinance/current_code.txt")
73
- # return {"messagecode":code}
74
- # elif "current_code.txt" not in os.listdir(f"{CURRENT_DIR}/CaesarFinance"):
75
- # return {"message":"temporary code doesn't exist. Please authenticate"}
76
 
77
  @app.websocket("/caesarobjectdetectws")
78
  async def caesarobjectdetectws(websocket: WebSocket):
 
55
  def caesarailogo():
56
  return FileResponse(f"{CURRENT_DIR}/CaesarAILogo.png")
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  @app.websocket("/caesarobjectdetectws")
60
  async def caesarobjectdetectws(websocket: WebSocket):