main.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pip install fastapi
  2. #pip install uvicorn
  3. import redis
  4. from fastapi import FastAPI,Form, Request
  5. import json
  6. import uvicorn
  7. import zipfile
  8. import json
  9. from fastapi.middleware.cors import CORSMiddleware
  10. app = FastAPI()
  11. app.add_middleware(
  12. CORSMiddleware,
  13. allow_origins=['*'],
  14. allow_credentials=True,
  15. allow_methods=["*"],
  16. allow_headers=["*"],
  17. )
  18. @app.get("/getbtn")
  19. def read_root(request: Request):
  20. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  21. data=r.get('btn_data')
  22. return json.loads(data)
  23. @app.get("/getliff3")
  24. def liff3(request: Request):
  25. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  26. data=r.get('liff3')
  27. return json.loads(data)
  28. @app.get("/news")
  29. def news(request: Request):
  30. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  31. data=r.get('liffnews')
  32. return json.loads(data)
  33. @app.get("/liff2-taroboba-yuan")
  34. def liff_taro(request: Request):
  35. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  36. data=r.get('liff2-taroboba-yuan')
  37. return json.loads(data)
  38. @app.get("/taiwanesefood666888")
  39. def liff_taro(request: Request):
  40. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  41. data=r.get('taiwanesefood666888')
  42. return json.loads(data)
  43. @app.get("/expofest")
  44. def liff_taro(request: Request):
  45. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  46. data=r.get('expofest')
  47. return json.loads(data)
  48. @app.get("/misa")
  49. def liff_taro(request: Request):
  50. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  51. data=r.get('misa')
  52. return json.loads(data)
  53. @app.get("/misa-liff")
  54. def news(request: Request):
  55. r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
  56. data=r.get('misa-liff2')
  57. return json.loads(data)
  58. if __name__ == "__main__":
  59. uvicorn.run("main:app", host="0.0.0.0", port=9898,ssl_keyfile='/etc/letsencrypt/live/liff.googo.org/privkey.pem',ssl_certfile='/etc/letsencrypt/live/liff.googo.org/cert.pem')
  60. #--ssl-keyfile=/etc/letsencrypt/www.choozmo.com/privkey1.pem --ssl-certfile=/etc/letsencrypt/www.choozmo.com/cert1.pem
  61. #/etc/letsencrypt/live/liff.googo.org