|
@@ -9,6 +9,10 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
|
import json
|
|
|
import urllib.request
|
|
|
import dataset,json
|
|
|
+import pandas as pd
|
|
|
+from gspread_pandas import Spread, Client
|
|
|
+from oauth2client.service_account import ServiceAccountCredentials
|
|
|
+import gspread
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
@@ -50,6 +54,7 @@ async def add_subclient_info(req:subreq):
|
|
|
sub_table = db['Subscribe']
|
|
|
time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
pk = sub_table.insert({'email':req.email,'timestamp':time_stamp})
|
|
|
+ make_ci_df()
|
|
|
return {'msg':code}
|
|
|
|
|
|
@app.get("/get_sub_list")
|
|
@@ -58,4 +63,27 @@ async def add_subclient_info():
|
|
|
result = []
|
|
|
for row in db.query(statement):
|
|
|
result += [{'id':row['id'],'email':row['email'],'timeStamp':row['timestamp']}]
|
|
|
- return result
|
|
|
+ return result
|
|
|
+
|
|
|
+
|
|
|
+def make_ci_df():
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/NFTBoard?charset=utf8mb4')
|
|
|
+ statement = 'SELECT * FROM Subscribe ORDER BY timestamp DESC'
|
|
|
+ #2021-05-23 15:57:43
|
|
|
+ df = pd.DataFrame()
|
|
|
+ for row in db.query(statement):
|
|
|
+ date_format = "%Y-%M-%d %H:%M:%S"
|
|
|
+ fdate = row['timestamp'].strftime('%Y-%m-%d %H時 %M分')
|
|
|
+
|
|
|
+ df = df.append({'serial id':row['id'],'e-mail':row['email'],'登記時間':fdate}, ignore_index=True)
|
|
|
+
|
|
|
+ df = df[['serial id','e-mail','登記時間']]
|
|
|
+ save_sheet(df,'subscribe_rec','Sheet1')
|
|
|
+
|
|
|
+def save_sheet(df,filename,tabname,startpos='A1'):
|
|
|
+ scope = ['https://spreadsheets.google.com/feeds',
|
|
|
+ 'https://www.googleapis.com/auth/drive']
|
|
|
+ credentials = ServiceAccountCredentials.from_json_keyfile_name('spread2.json', scope)
|
|
|
+ gc = gspread.authorize(credentials)
|
|
|
+ spread = Spread(filename,creds=credentials)
|
|
|
+ spread.df_to_sheet(df, sheet=tabname, start=startpos, replace=True)
|