Browse Source

add utm_source

aaron-1015 3 years ago
parent
commit
b002485759
2 changed files with 7 additions and 5 deletions
  1. 4 2
      step_question/apis/main.py
  2. 3 3
      step_question/tests/dftest.py

+ 4 - 2
step_question/apis/main.py

@@ -135,7 +135,8 @@ async def submit(request: Request):
         'decoration_budget': ','.join(form_data.getlist('q7')),
         'decoration_size': ','.join(form_data.getlist('q8')),
         'src':'SMS', 
-        'time_stamp': datetime.datetime.utcnow() + datetime.timedelta(hours=8)
+        'time_stamp': datetime.datetime.utcnow() + datetime.timedelta(hours=8),
+        'utm_source': form_data.get('utm_source')
     }
     print(result)
 
@@ -170,7 +171,8 @@ async def line_submit(request: Request):
         'userid': form_data.get('userid'),
 #        'id': form_data.get('id'),
         'area': form_data.get('area'),
-        'time_stamp': datetime.datetime.utcnow() + datetime.timedelta(hours=8)
+        'time_stamp': datetime.datetime.utcnow() + datetime.timedelta(hours=8),
+        'utm_source': form_data.get('utm_source')
     }
     if result['userid']==None:
         result['userid']="None"

+ 3 - 3
step_question/tests/dftest.py

@@ -32,13 +32,13 @@ def save_sheet(df,filename,tabname,startpos='A1'):
 
 def do_jobs():
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
-    cursor=db.query('SELECT sex,phone,email,building_case_name,building_case_type,decoration_style,decoration_budget,decoration_size,src,area,userid,time_stamp FROM hhh.step_questions;')
-    df = pd.DataFrame(columns=('sex','phone','email','building_case_name','building_case_type','decoration_style','decoration_budget','decoration_size','src','area','userid', 'time_stamp'))
+    cursor=db.query('SELECT sex,phone,email,building_case_name,building_case_type,decoration_style,decoration_budget,decoration_size,src,area,userid,time_stamp, utm_source FROM hhh.step_questions;')
+    df = pd.DataFrame(columns=('sex','phone','email','building_case_name','building_case_type','decoration_style','decoration_budget','decoration_size','src','area','userid', 'time_stamp', 'utm_source'))
 
     idx=0
 
     for c in cursor:
-        df.loc[idx]=[c['time_stamp'], c['sex'],c['phone'],c['email'],c['building_case_name'],c['building_case_type'],c['decoration_style'],c['decoration_budget'],c['decoration_size'],c['src'],c['area'],c['userid']]
+        df.loc[idx]=[c['time_stamp'], c['utm_source'], c['sex'],c['phone'],c['email'],c['building_case_name'],c['building_case_type'],c['decoration_style'],c['decoration_budget'],c['decoration_size'],c['src'],c['area'],c['userid']]
     #    df.loc[idx]=['okok',333]
         idx+=1
     save_sheet(df,'SurveyResult','result')