|
@@ -1,6 +1,7 @@
|
|
from wechat_action.sql_tools import save_wechat_cookies, save_human_info, delete_wechat_info, save_wechat_info
|
|
from wechat_action.sql_tools import save_wechat_cookies, save_human_info, delete_wechat_info, save_wechat_info
|
|
from wechat_api.get_wechat_info import WechatApi
|
|
from wechat_api.get_wechat_info import WechatApi
|
|
-from wechat_action.create_ad import CreateAd
|
|
|
|
|
|
+from wechat_action.create_ad_layout import CreateAd
|
|
|
|
+from wechat_action.create_ad_plan import CreateAdPlan
|
|
from wechat_action import sql_tools
|
|
from wechat_action import sql_tools
|
|
from sqlalchemy import Table
|
|
from sqlalchemy import Table
|
|
import json
|
|
import json
|
|
@@ -134,6 +135,7 @@ def create_layout(user_id, layout_name, wechat_json, log_ad, db, cookie_canuse):
|
|
return
|
|
return
|
|
print(typesetting_json)
|
|
print(typesetting_json)
|
|
typesetting_dict = json.loads(typesetting_json)
|
|
typesetting_dict = json.loads(typesetting_json)
|
|
|
|
+ typesetting_dict[-4] = {'layout_name': layout_name}
|
|
# action 进行对应记录
|
|
# action 进行对应记录
|
|
wechat_json = json.loads(wechat_json)
|
|
wechat_json = json.loads(wechat_json)
|
|
for _ in wechat_json:
|
|
for _ in wechat_json:
|
|
@@ -148,45 +150,102 @@ def create_layout(user_id, layout_name, wechat_json, log_ad, db, cookie_canuse):
|
|
for _ in wechat_json:
|
|
for _ in wechat_json:
|
|
service_name = _['service_name']
|
|
service_name = _['service_name']
|
|
wechat_name = _['wechat_name']
|
|
wechat_name = _['wechat_name']
|
|
|
|
+ # 检查落地页之前有无创建过
|
|
|
|
+ layout_num = sql_tools.check_layout_alive(sql_session, service_name, wechat_name, layout_name)
|
|
|
|
+ if layout_num:
|
|
|
|
+ continue
|
|
log_ad.select_ad_master(service_name, wechat_name)
|
|
log_ad.select_ad_master(service_name, wechat_name)
|
|
- res = CreateAd(login_ad=log_ad, user_id=user_id).create_layout(typesetting_dict)
|
|
|
|
|
|
+ res = CreateAd(login_ad=log_ad, service_name=service_name, wechat_name=wechat_name).create_layout(
|
|
|
|
+ typesetting_dict)
|
|
print(res)
|
|
print(res)
|
|
if not res['sucess']:
|
|
if not res['sucess']:
|
|
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
try:
|
|
try:
|
|
- log_ad.driver.save_screenshot('{layout_name}-{now_time}-{service_name}-{wechat_name}.png'.format(
|
|
|
|
- layout_name=layout_name,
|
|
|
|
- now_time=now_time,
|
|
|
|
- service_name=service_name,
|
|
|
|
- wechat_name=wechat_name))
|
|
|
|
|
|
+ log_ad.driver.save_screenshot(
|
|
|
|
+ 'create_ad_layout-{layout_name}-{now_time}-{service_name}-{wechat_name}.png'.format(
|
|
|
|
+ layout_name=layout_name,
|
|
|
|
+ now_time=now_time,
|
|
|
|
+ service_name=service_name,
|
|
|
|
+ wechat_name=wechat_name))
|
|
except:
|
|
except:
|
|
pass
|
|
pass
|
|
- # 截图,传回错误信息
|
|
|
|
|
|
+ # TODO:截图,传回错误信息
|
|
|
|
|
|
- status = 'done' if res['sucess'] else 'error'
|
|
|
|
- action_type = json.dumps({'action_type': 'layout_create', 'object_name': layout_name})
|
|
|
|
- # TODO:线上落地页名字进行设置
|
|
|
|
- update_res = action_record_table.update() \
|
|
|
|
- .where(action_record_table.c.service_name == service_name) \
|
|
|
|
- .where(action_record_table.c.wechat_name == wechat_name) \
|
|
|
|
- .where(action_record_table.c.user_id == user_id) \
|
|
|
|
- .where(action_record_table.c.action_type == action_type) \
|
|
|
|
- .values({
|
|
|
|
- action_record_table.c.status: status,
|
|
|
|
- action_record_table.c.result: res['result_info']
|
|
|
|
- })
|
|
|
|
- # values 添加两个列
|
|
|
|
- sql_session.execute(update_res)
|
|
|
|
- sql_session.commit()
|
|
|
|
|
|
+ sql_tools.action_record(res, sql_session, user_id, layout_name, action_record_table, service_name, wechat_name)
|
|
log_ad.refresh_driver()
|
|
log_ad.refresh_driver()
|
|
|
|
|
|
-
|
|
|
|
# 成功一个record,更新一个record
|
|
# 成功一个record,更新一个record
|
|
- log_ad.refresh_driver()
|
|
|
|
|
|
+ log_ad.driver.quite()
|
|
|
|
|
|
|
|
|
|
-def create_ad_plan():
|
|
|
|
- pass
|
|
|
|
|
|
+def create_ad_plan(user_id, ad_plan_name, wechat_json, log_ad, db, cookie_canuse):
|
|
|
|
+ # TODO:
|
|
|
|
+ # 1.任务有不断中途新增,该如何操作.------只管
|
|
|
|
+ # 2.落地页创建一半失败了怎么办
|
|
|
|
+ # 4.cookie记录每次刷新都会失效,需要改进
|
|
|
|
+
|
|
|
|
+ action_record_table = Table('action_record', db.metadata,
|
|
|
|
+ autoload=True, autoload_with=db.engine)
|
|
|
|
+ sql_session = db.DBSession()
|
|
|
|
+ # 等待页面加载完成
|
|
|
|
+
|
|
|
|
+ # 1.cookies保存
|
|
|
|
+ cookie_acion(db, log_ad, cookie_canuse, user_id)
|
|
|
|
+
|
|
|
|
+ # 获取到对应layout
|
|
|
|
+ typesetting_json = sql_tools.get_ad_plan_typesetting(sql_session=sql_session, user_id=user_id,
|
|
|
|
+ typesetting_name=ad_plan_name)
|
|
|
|
+ if not typesetting_json:
|
|
|
|
+ return
|
|
|
|
+ print(typesetting_json)
|
|
|
|
+ typesetting_dict = json.loads(typesetting_json)
|
|
|
|
+ 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']
|
|
|
|
+ wechat_name = _['wechat_name']
|
|
|
|
+ # 检查这个名字是否已经创建过
|
|
|
|
+ layout_name = typesetting_dict['idea']['jump_type-page_type']
|
|
|
|
+ if not sql_tools.check_layout_alive(sql_session, service_name, wechat_name, layout_name):
|
|
|
|
+ res = {'sucess': False, 'result_info': '公众号对应落地页未创建'}
|
|
|
|
+ sql_tools.action_record(res, sql_session, user_id, ad_plan_name, action_record_table, service_name,
|
|
|
|
+ wechat_name)
|
|
|
|
+ continue
|
|
|
|
+ if sql_tools.check_plan_alive(sql_session, service_name, wechat_name, ad_plan_name):
|
|
|
|
+ continue
|
|
|
|
+ log_ad.select_ad_master(service_name, wechat_name)
|
|
|
|
+ res = CreateAdPlan(login_ad=log_ad, task=typesetting_dict).run()
|
|
|
|
+ print(res)
|
|
|
|
+ if not res['sucess']:
|
|
|
|
+ now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
+ try:
|
|
|
|
+ log_ad.driver.save_screenshot(
|
|
|
|
+ 'create_ad_plan-{plan_name}-{now_time}-{service_name}-{wechat_name}.png'.format(
|
|
|
|
+ plan_name=ad_plan_name,
|
|
|
|
+ now_time=now_time,
|
|
|
|
+ service_name=service_name,
|
|
|
|
+ wechat_name=wechat_name))
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+ # 截图,传回错误信息
|
|
|
|
+
|
|
|
|
+ sql_tools.action_record(res, sql_session, user_id, ad_plan_name, action_record_table, service_name, wechat_name)
|
|
|
|
+ log_ad.refresh_driver()
|
|
|
|
+
|
|
|
|
+ # 成功一个record,更新一个record
|
|
|
|
+ log_ad.driver.quit()
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|