#pip install fastapi
#pip install uvicorn
import redis
from fastapi import FastAPI,Form, Request
import json
import uvicorn
import zipfile
import json

from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/getbtn")
def read_root(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('btn_data')
    return json.loads(data)


@app.get("/getliff3")
def liff3(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('liff3')
    return json.loads(data)


@app.get("/news")
def news(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('liffnews')
    return json.loads(data)

@app.get("/liff2-taroboba-yuan")
def liff_taro(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('liff2-taroboba-yuan')
    return json.loads(data)

@app.get("/taiwanesefood666888")
def liff_taro(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('taiwanesefood666888')
    return json.loads(data)

@app.get("/expofest")
def liff_taro(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('expofest')
    return json.loads(data)


@app.get("/misa")
def liff_taro(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('misa')
    return json.loads(data)

@app.get("/misa-liff")
def news(request: Request):
    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
    data=r.get('misa-liff2')
    return json.loads(data)

if __name__ == "__main__":
    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')
    
#--ssl-keyfile=/etc/letsencrypt/www.choozmo.com/privkey1.pem --ssl-certfile=/etc/letsencrypt/www.choozmo.com/cert1.pem

#/etc/letsencrypt/live/liff.googo.org
