|  | @@ -7,8 +7,8 @@ from sqlalchemy import Table
 | 
	
		
			
				|  |  |  import json
 | 
	
		
			
				|  |  |  import time
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -layout_create_action = 'layout_create'
 | 
	
		
			
				|  |  | -ad_plan_create_action = 'ad_plan_create'
 | 
	
		
			
				|  |  | +layout_create_action = 'create_ad_layout'
 | 
	
		
			
				|  |  | +ad_plan_create_action = 'create_ad_plan'
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def run(user_id, log_ad, db, cookie_canuse):
 | 
	
	
		
			
				|  | @@ -53,9 +53,54 @@ def cookie_acion(db, log_ad, cookie_canuse, user_id):
 | 
	
		
			
				|  |  |              sql_session.commit()
 | 
	
		
			
				|  |  |          print('update wechat cookies')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def carry_plan():
 | 
	
		
			
				|  |  | -    #TODO:action_record涉及到的地方都需要改动
 | 
	
		
			
				|  |  | -    pass
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def carry_plan(user_id, ad_plan_list, log_ad, db, cookie_canuse):
 | 
	
		
			
				|  |  | +    # TODO:action_record涉及到的地方都需要改动
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    action_record_table = Table('action_record', db.metadata,
 | 
	
		
			
				|  |  | +                                autoload=True, autoload_with=db.engine)
 | 
	
		
			
				|  |  | +    sql_session = db.DBSession()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    # cookies保存
 | 
	
		
			
				|  |  | +    cookie_acion(db, log_ad, cookie_canuse, user_id)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for _ in ad_plan_list:
 | 
	
		
			
				|  |  | +        service_name = _['service_name']
 | 
	
		
			
				|  |  | +        wechat_name = _['wechat_name']
 | 
	
		
			
				|  |  | +        # 1.检查1.落地页是否创建过了
 | 
	
		
			
				|  |  | +        log_ad.select_ad_master(service_name, wechat_name)
 | 
	
		
			
				|  |  | +        create_ad_layout = CreateAd(login_ad=log_ad, service_name=service_name, wechat_name=wechat_name)
 | 
	
		
			
				|  |  | +        create_ad_layout.check_sucess_ready()
 | 
	
		
			
				|  |  | +        # TODO:现在默认layout_name在30个字符以内
 | 
	
		
			
				|  |  | +        layout_name = _['idea']['jump_type_page_type']['layout_name'].replace(' ', '')[:29]
 | 
	
		
			
				|  |  | +        if create_ad_layout.check_sucess(layout_name=layout_name):
 | 
	
		
			
				|  |  | +            res = {'sucess': True, 'result_info': '已经创建过对应落地页'}
 | 
	
		
			
				|  |  | +            sql_tools.action_record(res, sql_session, layout_create_action, user_id, layout_name, action_record_table,
 | 
	
		
			
				|  |  | +                                    service_name, wechat_name)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            # 1.5无则创建落地页
 | 
	
		
			
				|  |  | +            create_ad_layout.get_into_create_page()
 | 
	
		
			
				|  |  | +            layout_typesetting_dict = sql_tools.get_layout_typesetting(sql_session, user_id,
 | 
	
		
			
				|  |  | +                                                                       typesetting_name=layout_name)
 | 
	
		
			
				|  |  | +            layout_typesetting_dict = json.loads(layout_typesetting_dict)
 | 
	
		
			
				|  |  | +            res = create_ad_layout.create_layout(layout_typesetting_dict)
 | 
	
		
			
				|  |  | +            sql_tools.action_record(res, sql_session, layout_create_action, user_id, layout_name, action_record_table,
 | 
	
		
			
				|  |  | +                                    service_name, wechat_name)
 | 
	
		
			
				|  |  | +        log_ad.refresh_driver()
 | 
	
		
			
				|  |  | +        # 3.创建计划
 | 
	
		
			
				|  |  | +        # TODO:添加计划是否创建检查,现默认计划没有重复
 | 
	
		
			
				|  |  | +        log_ad.select_ad_master(service_name, wechat_name)
 | 
	
		
			
				|  |  | +        plan_name = _['title'].replace(' ', '')[:29]
 | 
	
		
			
				|  |  | +        # plan_typesetting_dict = sql_tools.get_ad_plan_typesetting(sql_session=sql_session, user_id=user_id,
 | 
	
		
			
				|  |  | +        #                                                           typesetting_name=plan_name)
 | 
	
		
			
				|  |  | +        create_ad_plan = CreateAdPlan(login_ad=log_ad, task=_)
 | 
	
		
			
				|  |  | +        res = create_ad_plan.run()
 | 
	
		
			
				|  |  | +        # 4.更新action_record相关计划信息
 | 
	
		
			
				|  |  | +        sql_tools.action_record(res, sql_session, ad_plan_create_action, user_id, plan_name, action_record_table,
 | 
	
		
			
				|  |  | +                                service_name, wechat_name)
 | 
	
		
			
				|  |  | +        #TODO:添加final ,来关闭chrome
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # TODO:这里都是线程调度的函数,设定线程生命周期最长60分钟
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -133,7 +178,7 @@ def create_layout(user_id, layout_name, wechat_json, log_ad, db, cookie_canuse):
 | 
	
		
			
				|  |  |      sql_session = db.DBSession()
 | 
	
		
			
				|  |  |      # 等待页面加载完成
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    # 1.cookies保存
 | 
	
		
			
				|  |  | +    # cookies保存
 | 
	
		
			
				|  |  |      cookie_acion(db, log_ad, cookie_canuse, user_id)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 获取到对应layout
 | 
	
	
		
			
				|  | @@ -146,14 +191,6 @@ def create_layout(user_id, layout_name, wechat_json, log_ad, db, cookie_canuse):
 | 
	
		
			
				|  |  |      typesetting_dict[-4] = {'layout_name': layout_name}
 | 
	
		
			
				|  |  |      # action 进行对应记录
 | 
	
		
			
				|  |  |      wechat_json = json.loads(wechat_json)
 | 
	
		
			
				|  |  | -    for _ in wechat_json:
 | 
	
		
			
				|  |  | -        action_info = {'user_id': user_id, 'service_name': _['service_name'], 'wechat_name': _['wechat_name'],
 | 
	
		
			
				|  |  | -                       'action_type': json.dumps({'action_type': layout_create_action, 'object_name': layout_name}),
 | 
	
		
			
				|  |  | -                       'status': 'todo'}
 | 
	
		
			
				|  |  | -        record_insert = sql_tools.save_action_record(action_record_info=action_info,
 | 
	
		
			
				|  |  | -                                                     table_action_record=action_record_table)
 | 
	
		
			
				|  |  | -        sql_session.execute(record_insert)
 | 
	
		
			
				|  |  | -        sql_session.commit()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      for _ in wechat_json:
 | 
	
		
			
				|  |  |          service_name = _['service_name']
 | 
	
	
		
			
				|  | @@ -179,6 +216,7 @@ def create_layout(user_id, layout_name, wechat_json, log_ad, db, cookie_canuse):
 | 
	
		
			
				|  |  |                  pass
 | 
	
		
			
				|  |  |              # TODO:截图,传回错误信息
 | 
	
		
			
				|  |  |          action_type = layout_create_action
 | 
	
		
			
				|  |  | +        # TODO:进行对应数据修改
 | 
	
		
			
				|  |  |          sql_tools.action_record(res, sql_session, action_type, user_id, layout_name, action_record_table, service_name,
 | 
	
		
			
				|  |  |                                  wechat_name)
 | 
	
		
			
				|  |  |          log_ad.refresh_driver()
 | 
	
	
		
			
				|  | @@ -212,16 +250,6 @@ def create_ad_plan(user_id, ad_plan_name, wechat_json, log_ad, db, cookie_canuse
 | 
	
		
			
				|  |  |      typesetting_dict['title'] = ad_plan_name
 | 
	
		
			
				|  |  |      # action 进行对应记录
 | 
	
		
			
				|  |  |      wechat_json = json.loads(wechat_json)
 | 
	
		
			
				|  |  | -    for _ in wechat_json:
 | 
	
		
			
				|  |  | -        # TODO:有时间看看 create_layout与create_ad_plan是否需要合并
 | 
	
		
			
				|  |  | -        # TODO:action_type 名字设置
 | 
	
		
			
				|  |  | -        action_info = {'user_id': user_id, 'service_name': _['service_name'], 'wechat_name': _['wechat_name'],
 | 
	
		
			
				|  |  | -                       'action_type': json.dumps({'action_type': 'ad_plan_create', 'object_name': ad_plan_name}),
 | 
	
		
			
				|  |  | -                       'status': 'todo'}
 | 
	
		
			
				|  |  | -        record_insert = sql_tools.save_action_record(action_record_info=action_info,
 | 
	
		
			
				|  |  | -                                                     table_action_record=action_record_table)
 | 
	
		
			
				|  |  | -        sql_session.execute(record_insert)
 | 
	
		
			
				|  |  | -        sql_session.commit()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      for _ in wechat_json:
 | 
	
		
			
				|  |  |          service_name = _['service_name']
 |