Jitendra12421 commited on
Commit
4ec2b76
·
verified ·
1 Parent(s): 70f6e35

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -29
app.py CHANGED
@@ -1,14 +1,12 @@
1
  from __future__ import annotations
2
 
3
  import asyncio
4
- import hmac
5
- import os
6
  from datetime import date, datetime, time, timedelta
7
 
8
  import sys
9
  from pathlib import Path
10
 
11
- from fastapi import Body, Depends, Header, HTTPException, Query
12
  from fastapi.middleware.cors import CORSMiddleware
13
  from fastapi import FastAPI
14
 
@@ -42,10 +40,6 @@ FIRST5_READY = time(9, 20)
42
  MARKET_CLOSE = time(15, 30)
43
 
44
 
45
- def configured_pin() -> str:
46
- return os.getenv("DASHBOARD_PIN", "1979")
47
-
48
-
49
  def latest_prediction_date(payload: dict | None = None) -> date | None:
50
  try:
51
  latest = payload if payload is not None else latest_saved_prediction()
@@ -136,20 +130,6 @@ def attach_market_state(payload: dict) -> dict:
136
  return payload
137
 
138
 
139
- def verify_pin(pin: str | None) -> None:
140
- if not pin or not hmac.compare_digest(pin, configured_pin()):
141
- raise HTTPException(status_code=401, detail="Invalid PIN")
142
-
143
-
144
- def verify_pin_header(
145
- x_dashboard_pin: str | None = Header(default=None),
146
- authorization: str | None = Header(default=None),
147
- ) -> None:
148
- pin = x_dashboard_pin
149
- if not pin and authorization and authorization.lower().startswith("bearer "):
150
- pin = authorization[7:].strip()
151
- verify_pin(pin)
152
-
153
  async def daily_ist_refresh_loop() -> None:
154
  global market_status
155
  while True:
@@ -247,13 +227,7 @@ def root() -> dict[str, str]:
247
 
248
 
249
  @app.get("/dashboard")
250
- def dashboard(_: None = Depends(verify_pin_header)) -> dict:
251
- return attach_market_state(dashboard_payload())
252
-
253
-
254
- @app.post("/dashboard/unlock")
255
- def dashboard_unlock(body: dict = Body(default_factory=dict)) -> dict:
256
- verify_pin(str(body.get("pin", "")))
257
  return attach_market_state(dashboard_payload())
258
 
259
 
@@ -263,7 +237,7 @@ def cron_keepalive() -> dict:
263
 
264
 
265
  @app.get("/prediction/latest")
266
- def prediction_latest(_: None = Depends(verify_pin_header)) -> dict:
267
  return latest_saved_prediction()
268
 
269
 
 
1
  from __future__ import annotations
2
 
3
  import asyncio
 
 
4
  from datetime import date, datetime, time, timedelta
5
 
6
  import sys
7
  from pathlib import Path
8
 
9
+ from fastapi import Query
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi import FastAPI
12
 
 
40
  MARKET_CLOSE = time(15, 30)
41
 
42
 
 
 
 
 
43
  def latest_prediction_date(payload: dict | None = None) -> date | None:
44
  try:
45
  latest = payload if payload is not None else latest_saved_prediction()
 
130
  return payload
131
 
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  async def daily_ist_refresh_loop() -> None:
134
  global market_status
135
  while True:
 
227
 
228
 
229
  @app.get("/dashboard")
230
+ def dashboard() -> dict:
 
 
 
 
 
 
231
  return attach_market_state(dashboard_payload())
232
 
233
 
 
237
 
238
 
239
  @app.get("/prediction/latest")
240
+ def prediction_latest() -> dict:
241
  return latest_saved_prediction()
242
 
243