|  | @@ -14,7 +14,7 @@ import datetime
 | 
											
												
													
														|  |  from gspread_pandas import Spread, Client
 |  |  from gspread_pandas import Spread, Client
 | 
											
												
													
														|  |  from oauth2client.service_account import ServiceAccountCredentials
 |  |  from oauth2client.service_account import ServiceAccountCredentials
 | 
											
												
													
														|  |  import os
 |  |  import os
 | 
											
												
													
														|  | -import thread
 |  | 
 | 
											
												
													
														|  | 
 |  | +import threading
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  def save_sheet(df,filename,tabname,startpos='A1'):
 |  |  def save_sheet(df,filename,tabname,startpos='A1'):
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -28,24 +28,20 @@ def save_sheet(df,filename,tabname,startpos='A1'):
 | 
											
												
													
														|  |      spread.df_to_sheet(df, index=False, sheet=tabname, start=startpos, replace=False)
 |  |      spread.df_to_sheet(df, index=False, sheet=tabname, start=startpos, replace=False)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +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 FROM hhh.step_questions;')
 | 
											
												
													
														|  | 
 |  | +    df = pd.DataFrame(columns=('sex','phone','email','building_case_name','building_case_type','decoration_style','decoration_budget','decoration_size'))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    idx=0
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
 |  | 
 | 
											
												
													
														|  | 
 |  | +    for c in cursor:
 | 
											
												
													
														|  | 
 |  | +        df.loc[idx]=[c['sex'],c['phone'],c['email'],c['building_case_name'],c['building_case_type'],c['decoration_style'],c['decoration_budget'],c['decoration_size']]
 | 
											
												
													
														|  | 
 |  | +    #    df.loc[idx]=['okok',333]
 | 
											
												
													
														|  | 
 |  | +        idx+=1
 | 
											
												
													
														|  | 
 |  | +    save_sheet(df,'SurveyResult','result')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -#db = dataset.connect('mysql://jared:Sstc_5202@home.a4.monster:7036/finance2?charset=utf8mb4')
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -#db=get_db()
 |  | 
 | 
											
												
													
														|  | -cursor=db.query('SELECT sex,phone,email,building_case_name,building_case_type,decoration_style,decoration_budget,decoration_size FROM hhh.step_questions;')
 |  | 
 | 
											
												
													
														|  | -df = pd.DataFrame(columns=('sex','phone','email','building_case_name','building_case_type','decoration_style','decoration_budget','decoration_size'))
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -idx=0
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -for c in cursor:
 |  | 
 | 
											
												
													
														|  | -    df.loc[idx]=[c['sex'],c['phone'],c['email'],c['building_case_name'],c['building_case_type'],c['decoration_style'],c['decoration_budget'],c['decoration_size']]
 |  | 
 | 
											
												
													
														|  | -#    df.loc[idx]=['okok',333]
 |  | 
 | 
											
												
													
														|  | -    idx+=1
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -save_sheet(df,'SurveyResult','result')
 |  | 
 | 
											
												
													
														|  | 
 |  | +t = threading.Thread(target = do_jobs)
 | 
											
												
													
														|  | 
 |  | +t.start()
 | 
											
												
													
														|  | 
 |  | +t.join()
 | 
											
												
													
														|  |  
 |  |  
 |