Spaces:
Runtime error
Runtime error
CaesarCloudSync
commited on
Commit
·
8723f10
1
Parent(s):
815392d
attempt streaming json response
Browse files- __pycache__/main.cpython-310.pyc +0 -0
- __pycache__/test2.cpython-310.pyc +0 -0
- main.py +14 -1
- test2.py +111 -7
__pycache__/main.cpython-310.pyc
CHANGED
Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ
|
|
__pycache__/test2.cpython-310.pyc
ADDED
Binary file (4.1 kB). View file
|
|
main.py
CHANGED
@@ -25,6 +25,7 @@ import json
|
|
25 |
import stripe
|
26 |
import jwt
|
27 |
#import cv2
|
|
|
28 |
import re
|
29 |
import jwt
|
30 |
from fastapi import FastAPI, Header
|
@@ -385,6 +386,17 @@ async def changerevisioncard(data : JSONStructure = None, authorization: str = H
|
|
385 |
|
386 |
@app.get('/getrevisioncards')# GET # allow all origins all methods.
|
387 |
async def getrevisioncards(authorization: str = Header(None)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
current_user = secure_decode(authorization.replace("Bearer ",""))["email"]
|
389 |
if current_user:
|
390 |
try:
|
@@ -392,7 +404,8 @@ async def getrevisioncards(authorization: str = Header(None)):
|
|
392 |
if email_exists: # Checks if email exists
|
393 |
user_revision_cards = list(importcsv.db.accountrevisioncards.find({"email": current_user}))[0]
|
394 |
del user_revision_cards["_id"],user_revision_cards["email"]
|
395 |
-
return user_revision_cards
|
|
|
396 |
elif not email_exists:
|
397 |
return {"message":"No revision cards"} # Send in shape of data
|
398 |
except Exception as ex:
|
|
|
25 |
import stripe
|
26 |
import jwt
|
27 |
#import cv2
|
28 |
+
from fastapi.responses import StreamingResponse
|
29 |
import re
|
30 |
import jwt
|
31 |
from fastapi import FastAPI, Header
|
|
|
386 |
|
387 |
@app.get('/getrevisioncards')# GET # allow all origins all methods.
|
388 |
async def getrevisioncards(authorization: str = Header(None)):
|
389 |
+
def iter_df(user_revision_cards):
|
390 |
+
for revisioncard in user_revision_cards["revisioncards"]:
|
391 |
+
#print(revisioncard)
|
392 |
+
revisioncard.update({"revisionscheduleinterval":revisioncard["revisionscheduleinterval"]})
|
393 |
+
yield json.dumps(revisioncard)
|
394 |
+
|
395 |
+
|
396 |
+
|
397 |
+
|
398 |
+
#
|
399 |
+
|
400 |
current_user = secure_decode(authorization.replace("Bearer ",""))["email"]
|
401 |
if current_user:
|
402 |
try:
|
|
|
404 |
if email_exists: # Checks if email exists
|
405 |
user_revision_cards = list(importcsv.db.accountrevisioncards.find({"email": current_user}))[0]
|
406 |
del user_revision_cards["_id"],user_revision_cards["email"]
|
407 |
+
return StreamingResponse(iter_df(user_revision_cards), media_type="application/json")
|
408 |
+
#return user_revision_cards
|
409 |
elif not email_exists:
|
410 |
return {"message":"No revision cards"} # Send in shape of data
|
411 |
except Exception as ex:
|
test2.py
CHANGED
@@ -1,10 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from raspsendemail import RaspEmail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
if __name__ == "__main__":
|
4 |
-
|
5 |
-
message = "Hello World"
|
6 |
-
subject = f"RevisionBank Send Now"
|
7 |
-
import requests
|
8 |
-
#requests.post("http://192.168.0.23:7860/revisionbanksendemail",json={"email":"[email protected]","subject":"RevisionBank New User","message":"RevisionBank New User"})
|
9 |
-
#RaspEmail.send(email = email,subject = subject,message = message,attachment = None)
|
10 |
-
#RaspEmail.send(**{"email":"[email protected]","subject":"RevisionBank New User","message":"RevisionBank New User"})
|
|
|
1 |
+
import base64
|
2 |
+
import concurrent
|
3 |
+
import os
|
4 |
+
from concurrent.futures import thread
|
5 |
+
from datetime import datetime
|
6 |
+
import datetime as dt
|
7 |
+
import requests
|
8 |
+
from bs4 import BeautifulSoup
|
9 |
+
from flask import Flask, app, jsonify, request
|
10 |
+
from flask_cors import CORS, cross_origin
|
11 |
+
from flask_mail import Mail, Message
|
12 |
+
from physicsaqa import PhysicsAQA
|
13 |
+
from config import Config
|
14 |
+
from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity
|
15 |
+
from csv_to_db import ImportCSV
|
16 |
+
from models import Users
|
17 |
+
from bson.objectid import ObjectId #
|
18 |
+
import hashlib
|
19 |
+
import random
|
20 |
+
from datetime import datetime
|
21 |
+
from PIL import Image, ImageOps
|
22 |
+
from io import BytesIO
|
23 |
+
import base64
|
24 |
+
import json
|
25 |
+
import stripe
|
26 |
+
import jwt
|
27 |
+
#import cv2
|
28 |
+
from fastapi.responses import StreamingResponse
|
29 |
+
from fastapi import WebSocket,WebSocketDisconnect
|
30 |
+
import re
|
31 |
+
import jwt
|
32 |
+
from fastapi import FastAPI, Header
|
33 |
+
from fastapi.middleware.cors import CORSMiddleware
|
34 |
+
from pydantic import BaseModel
|
35 |
+
from typing import Optional
|
36 |
+
from typing import Generic, TypeVar,Dict,List,AnyStr,Any,Union
|
37 |
+
import asyncio
|
38 |
+
import uvicorn
|
39 |
+
import pytesseract
|
40 |
+
from forgotpassemail import forgotpasswordemail
|
41 |
+
from RevisionBankModels import *
|
42 |
+
from fastapi_utils.tasks import repeat_every
|
43 |
from raspsendemail import RaspEmail
|
44 |
+
from revisionbankscheduler import RevisionBankScheduler
|
45 |
+
app = FastAPI()
|
46 |
+
app.add_middleware(
|
47 |
+
CORSMiddleware,
|
48 |
+
allow_origins=["*"],
|
49 |
+
allow_credentials=True,
|
50 |
+
allow_methods=["*"],
|
51 |
+
allow_headers=["*"],
|
52 |
+
)
|
53 |
+
importcsv = ImportCSV("RevisionBankDB",maindb=0)
|
54 |
+
importcsvqp = ImportCSV("RevisionBankDB",maindb= 1)
|
55 |
+
importcsvqp1 = ImportCSV("RevisionBankQPs1",maindb=2)
|
56 |
+
revisionbankschedule = RevisionBankScheduler(importcsv)
|
57 |
+
JWT_SECRET = "Peter Piper picked a peck of pickled peppers, A peck of pickled peppers Peter Piper picked, If Peter Piper picked a peck of pickled peppers,Where's the peck of pickled peppers Peter Piper picked" #'super-secret'
|
58 |
+
# IRL we should NEVER hardcode the secret: it should be an evironment variable!!!
|
59 |
+
JWT_ALGORITHM = "HS256"
|
60 |
+
|
61 |
+
JSONObject = Dict[Any, Any]
|
62 |
+
JSONArray = List[Any]
|
63 |
+
JSONStructure = Union[JSONArray, JSONObject]
|
64 |
+
time_hour = 60 * 60 # 1 hour,
|
65 |
+
|
66 |
+
with open("tets.json","r") as f:
|
67 |
+
user_revision_cards = json.load(f)
|
68 |
+
|
69 |
+
@app.get('/')# GET # allow all origins all methods.
|
70 |
+
async def index():
|
71 |
+
return "Hello World"
|
72 |
+
|
73 |
+
@app.get('/getrevisioncards')# GET # allow all origins all methods.
|
74 |
+
async def getrevisioncards():
|
75 |
+
def iter_df(user_revision_cards):
|
76 |
+
for revisioncard in user_revision_cards:
|
77 |
+
print(revisioncard)
|
78 |
+
yield json.dumps(revisioncard)
|
79 |
+
with open("tets.json","r") as f:
|
80 |
+
user_revision_cards= json.load(f)["revisioncards"]
|
81 |
+
|
82 |
+
try:
|
83 |
+
|
84 |
+
return StreamingResponse(iter_df(user_revision_cards), media_type="application/json")
|
85 |
+
#return user_revision_cards
|
86 |
+
|
87 |
+
except Exception as ex:
|
88 |
+
return {f"error":f"{type(ex)},{str(ex)}"}
|
89 |
+
#200OK, 62 ms, 19.89 KB
|
90 |
+
@app.websocket("/caesarobjectdetectws")
|
91 |
+
async def caesarobjectdetectws(websocket: WebSocket):
|
92 |
+
# listen for connections
|
93 |
+
await websocket.accept()
|
94 |
+
|
95 |
+
try:
|
96 |
+
while True:
|
97 |
+
contents = await websocket.receive_json()
|
98 |
+
print(contents)
|
99 |
+
if contents["message"] == "getcards":
|
100 |
+
for revisioncard in user_revision_cards["revisioncards"]:
|
101 |
+
await websocket.send_json(json.dumps(revisioncard)) # sends the buffer as bytes
|
102 |
+
|
103 |
+
|
104 |
+
except WebSocketDisconnect:
|
105 |
+
print("Client disconnected")
|
106 |
+
|
107 |
+
|
108 |
+
async def main():
|
109 |
+
config = uvicorn.Config("test2:app", port=7860, log_level="info",host="0.0.0.0",reload=True)
|
110 |
+
server = uvicorn.Server(config)
|
111 |
+
await server.serve()
|
112 |
|
113 |
if __name__ == "__main__":
|
114 |
+
asyncio.run(main())
|
|
|
|
|
|
|
|
|
|
|
|