| 
					
				 | 
			
			
				@@ -2,8 +2,11 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 # -*- coding: utf-8 -*- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 Created on Thu Jun  4 15:06:05 2020 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @author: chencong 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+updated by ck on 20201127 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import sys 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import requests 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,8 +23,6 @@ from concurrent.futures import ThreadPoolExecutor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from datetime import datetime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def md5value(s): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	md5 = hashlib.md5() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	md5.update(s.encode("utf-8")) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -110,34 +111,13 @@ def get_daily_qq(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return tuple(li) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-def mysql_insert_order(data): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	cursor = db.cursor() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	time1 = time.time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# sql = 'insert ignore into quchen_text.order (amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	sql = 'replace into quchen_text.order(amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		cursor.executemany(sql, data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		db.commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		cost_time = round((time.time() - time1) / 60, 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print('insert_order access', len(data), 'cost_minutes:', cost_time) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	except: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		db.rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print('insert_order defeat') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def mysql_insert_daily_vx(data): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	cursor = db.cursor() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	time1 = time.time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# sql1 = 'delete from daily_vx where date = %s' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	sql2 = 'replace into daily_vx (date,cost,view_count,valid_click_count,ctr,official_account_follow_rate,order_amount,order_roi,order_count,order_rate,order_unit_price,web_order_cost,first_day_order_amount,first_day_order_count,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime()))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	db.commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	print('clear_daily_vx access') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# except: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	print('clear_daily_vx defeat') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		cursor.executemany(sql2, data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		db.commit() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -152,14 +132,9 @@ def mysql_insert_daily_qq(data): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	cursor = db.cursor() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	time1 = time.time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# sql1 = 'delete from daily_qq where date = %s' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	sql2 = 'replace into daily_qq (date,view_count,valid_click_count,ctr,cpc,cost,web_order_count,web_order_rate,web_order_cost,follow_count,order_amount,order_roi,platform_page_view_count,web_commodity_page_view_count,from_follow_uv,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime()))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	db.commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	print('clear_daily_qq access') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# except: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# 	print('clear_daily_qq defeat') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		cursor.executemany(sql2, data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		db.commit() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -197,15 +172,26 @@ def start_cost_job(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	mysql_insert_daily_qq(get_daily_qq()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if __name__ == '__main__': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	print("start_at ===================="+str(datetime.today())+"===================") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	max_workers = 5 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	my_time = datetime.today().strftime('%Y-%m-%d') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if sys.argv.__len__() ==2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		yestoday=(datetime.today()-timedelta(days=1)).strftime('%Y-%m-%d') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my_time=yestoday 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print("跑昨天["+yestoday+"]数据") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# my_time = '2020-11-24' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if sys.argv.__len__() == 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		yestoday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		my_time = yestoday 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print("跑昨天[" + yestoday + "]数据") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	start_cost_job() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# run history data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# i=3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 	my_time=(datetime.today()-timedelta(days=i)).strftime('%Y-%m-%d') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 	print("run["+my_time+"]data") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 	start_cost_job() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 	i+=1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 	if my_time=='2020-10-01': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	# 		break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |