|
@@ -17,6 +17,7 @@ import pandas as pd
|
|
|
from gspread_pandas import Spread, Client
|
|
|
from oauth2client.service_account import ServiceAccountCredentials
|
|
|
import gspread
|
|
|
+from first import first
|
|
|
app = FastAPI()
|
|
|
origins = [
|
|
|
"http://172.105.205.52",
|
|
@@ -101,6 +102,11 @@ class Course(BaseModel):
|
|
|
price_discount: int
|
|
|
hours: float
|
|
|
units: int
|
|
|
+
|
|
|
+class Email_tag(BaseModel):
|
|
|
+ email:str
|
|
|
+ tags:int[]
|
|
|
+
|
|
|
@app.post("/get_courses_by_cid")
|
|
|
async def get_courses(cids:List[int]):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
@@ -151,8 +157,7 @@ async def create_courses(tags: list,course:Course):
|
|
|
course_tag_table = db['course_tag']
|
|
|
for tag in tags:
|
|
|
course_tag_table.insert({'course_id':course.id,'tag_id':tag})
|
|
|
- x = threading.Thread(target=to_sheet)
|
|
|
- x.start()
|
|
|
+
|
|
|
return {'msg':'新增成功'}
|
|
|
|
|
|
@app.get("/del_course/{course_id}")
|
|
@@ -182,21 +187,30 @@ async def create_upload_file(file: UploadFile = File(...)):
|
|
|
image = Image.open(io.BytesIO(contents))
|
|
|
image= image.convert("RGB")
|
|
|
image.save(cover_img_dir+img_name+'.jpg')
|
|
|
-
|
|
|
return {"msg": serverADDR+cover_img_dir+img_name+'.jpg'}
|
|
|
|
|
|
+@app.get("/email_interest")
|
|
|
+async def email_interest(email_tag:Email_tag):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
|
+ email_table = db['interest_email']
|
|
|
+
|
|
|
+ for tag in email_tag.tags:
|
|
|
+ email_table.insert({'email':tag.name,'interest_tag':tag})
|
|
|
+ x = threading.Thread(target=to_sheet)
|
|
|
+ x.start()
|
|
|
+ return {'msg':'ok'}
|
|
|
+
|
|
|
|
|
|
def to_sheet():
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
|
- statement = 'SELECT * FROM course ORDER BY clicks DESC'
|
|
|
+ statement = 'SELECT DISTINCT email FROM interest_email '
|
|
|
|
|
|
df = pd.DataFrame()
|
|
|
for row in db.query(statement):
|
|
|
- date_format = "%Y-%M-%d %H:%M:%S"
|
|
|
-
|
|
|
- df = df.append({'serial id':row['id'],'標題':row['title'],'介紹':row['profile'],'url':row['url']
|
|
|
- ,'圖片':row['cover_img'],'價錢':row['price'],"折扣後價錢":row['price_discount'],'時數':row['hours']
|
|
|
- ,'單元數':row['units'],'點擊次數':row['clicks']}, ignore_index=True)
|
|
|
+ tag_names = ''
|
|
|
+ for row_tag in db.query('SELECT interest_tag FROM interest_email WHERE email='+row['email']):
|
|
|
+ tag_names += first(db.query('SELECT * FROM tag where id ='+str(row[tag])))['name']
|
|
|
+ df = df.append({'email':row['email'],'種類':tag_names}}, ignore_index=True)
|
|
|
save_sheet(df,'interest_email','index')
|
|
|
|
|
|
def save_sheet(df,filename,tabname,startpos='A1'):
|