|
@@ -34,6 +34,18 @@ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/NFTBoard?charset=u
|
|
|
class subreq(BaseModel):
|
|
|
email:str
|
|
|
|
|
|
+class ContactUs(BaseModel):
|
|
|
+ country_code: str
|
|
|
+ username: str
|
|
|
+ email: str
|
|
|
+ phone: str
|
|
|
+ coop_dif: Optional[bool] = 0
|
|
|
+ coop_ad: Optional[bool] = 0
|
|
|
+ coop_acting: Optional[bool] = 0
|
|
|
+ coop_marketing: Optional[bool] = 0
|
|
|
+ work_address: str
|
|
|
+
|
|
|
+
|
|
|
@app.get("/showdata/{limit}")
|
|
|
async def showdata(limit):
|
|
|
url = 'https://api.coinmarketcap.com/data-api/v3/nft/collections?start=0&limit=' + limit
|
|
@@ -62,6 +74,37 @@ async def add_subclient_info(req:subreq):
|
|
|
code = 0
|
|
|
return {'msg':code}#0 means succss added, 1 means email is duplicated
|
|
|
|
|
|
+
|
|
|
+@app.post('/add_contact_us')
|
|
|
+async def add_contact_us_client_info(req: ContactUs):
|
|
|
+ """ 新增Contact Us資料,先存入DB,並從DB撈回全部資料,更新Google Sheet. """
|
|
|
+ code = 1
|
|
|
+ table = db['ContactUs']
|
|
|
+ time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
+ statement = 'SELECT COUNT(1) FROM ContactUs WHERE email = "'+ req.email +'"'
|
|
|
+ if first(db.query(statement))['COUNT(1)'] == 0:
|
|
|
+ table.insert(
|
|
|
+ {
|
|
|
+ 'country_code':req.country_code,
|
|
|
+ 'username': req.username,
|
|
|
+ 'email': req.email,
|
|
|
+ 'phone': req.phone,
|
|
|
+ 'coop_dif': req.coop_dif,
|
|
|
+ 'coop_ad': req.coop_ad,
|
|
|
+ 'coop_acting': req.coop_acting,
|
|
|
+ 'coop_marketing': req.coop_marketing,
|
|
|
+ 'work_address': req.work_address,
|
|
|
+ 'timestamp': time_stamp
|
|
|
+ }
|
|
|
+ )
|
|
|
+ code = 0
|
|
|
+ # 更新sheet
|
|
|
+ make_contact_us_df()
|
|
|
+ return {'msg':code}#0 means succss added, 1 means email is duplicated
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@app.get("/get_sub_list")
|
|
|
async def add_subclient_info():
|
|
|
statement = 'SELECT * FROM Subscribe'
|
|
@@ -85,10 +128,23 @@ def make_ci_df():
|
|
|
df = df[['serial id','e-mail','登記時間']]
|
|
|
save_sheet(df,'subscribe_rec','Sheet1')
|
|
|
|
|
|
-def save_sheet(df,filename,tabname,startpos='A1'):
|
|
|
+
|
|
|
+def make_contact_us_df():
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/NFTBoard?charset=utf8mb4')
|
|
|
+ statement = 'SELECT * FROM ContactUs ORDER BY timestamp DESC'
|
|
|
+ df = pd.DataFrame()
|
|
|
+ for row in db.query(statement):
|
|
|
+
|
|
|
+ df = df.append({'id': row['id'], '國家區域': row['country_code'], '姓名': row['username'], '聯絡Email': row['email'], '聯絡手機': row['phone'], '合作方式_異業合作': row['coop_dif'], '合作方式_廣告刊登': row['coop_ad'], '合作方式_代理發行': row['coop_acting'], '合作方式_知識產權行銷': row['coop_marketing'], '作品連結': row['work_address'], '申請時間': row['timestamp']}, ignore_index=True)
|
|
|
+ df = df[['id', '國家區域', '姓名', '聯絡Email', '聯絡手機', '合作方式_異業合作', '合作方式_廣告刊登', '合作方式_代理發行', '合作方式_知識產權行銷', '作品連結', '申請時間']]
|
|
|
+ print(df)
|
|
|
+ save_sheet(df, '聯絡NFTBoard (回應)', 'Sheet1', json_name='cred.json')
|
|
|
+
|
|
|
+
|
|
|
+def save_sheet(df,filename,tabname,startpos='A1', json_name='spread2.json'):
|
|
|
scope = ['https://spreadsheets.google.com/feeds',
|
|
|
'https://www.googleapis.com/auth/drive']
|
|
|
- credentials = ServiceAccountCredentials.from_json_keyfile_name('spread2.json', scope)
|
|
|
+ credentials = ServiceAccountCredentials.from_json_keyfile_name(json_name, scope)
|
|
|
gc = gspread.authorize(credentials)
|
|
|
spread = Spread(filename,creds=credentials)
|
|
|
- spread.df_to_sheet(df, sheet=tabname, start=startpos, replace=True)
|
|
|
+ spread.df_to_sheet(df, sheet=tabname, start=startpos, replace=True, index=False)
|