main.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pip install fastapi
  2. #pip install uvicorn
  3. from fastapi.responses import HTMLResponse
  4. from fastapi import FastAPI,Form, Request,UploadFile
  5. from fastapi.templating import Jinja2Templates
  6. import uvicorn
  7. import zipfile
  8. from chz_gmail_temp import mail2
  9. from personal_settings import *
  10. app = FastAPI()
  11. templates=Jinja2Templates(directory="html_directory")
  12. @app.get("/email_test")
  13. def read_root(request: Request):
  14. return templates.TemplateResponse('home.html',{"request": request})
  15. @app.post("/submitform")
  16. def create_upload_file(file: UploadFile,username: str = Form(...)):
  17. file_location = "./templates/use_zip.zip"
  18. with open(file_location, 'wb+') as f:
  19. f.write(file.file.read())
  20. zf = zipfile.ZipFile(file_location, 'r')
  21. print(zf.namelist())
  22. zf.extractall("./templates/")
  23. mailobj={}
  24. mailobj['toaddr']=username
  25. mailobj['gmail_user']=gmail_user
  26. mailobj['gmail_password']=gmail_password
  27. mailobj['title'] = gmail_title
  28. mailobj['totext'] = gmail_totext
  29. mail2(mailobj)
  30. return "down"
  31. # return {"username": username,"filename": file.filename}
  32. if __name__ == "__main__":
  33. uvicorn.run("main:app", host="127.0.0.1", port=5000)
  34. # @app.get("/items/{item_id}")
  35. # def read_item(item_id: int, q: Optional[str] = None):
  36. # return {"item_id": item_id, "q": q}