123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- from sqlalchemy import create_engine
- from urllib import parse
- import pandas as pd
- import yaml
- with open('config/config.yaml', mode='r', encoding='utf-8') as f:
- config = yaml.load(f.read(), Loader=yaml.FullLoader)
- def update_dict(x, y):
- # 用字典y,来更新x
- # key 存在则更新,不存在则新增
- x.update(y)
- return x
- def get_db_engine(db_info):
- db_con_str = 'mysql+pymysql://%s:%s@%s:%d/%s' % \
- (db_info['username'],
- parse.quote_plus(db_info['password']),
- db_info['host'],
- db_info['port'],
- db_info['database'])
- engine = create_engine(db_con_str, connect_args={'charset': 'utf8'})
- return engine
- def is_contains_region(val1, val2):
- """
- level1
- region long[] 可选 地域 传值为[]表示不限;传递上一级ID时,childrenID可以不传;不允许同时传parentID和childrenID;
- 仅计划的campaign_type为5时,支持设置三级地域(例:山西-大同-左云,左云是三级地域)
- :param val1:
- :param val2:
- :return:
- """
- is_contains = False
- val = None
- city_lst = []
- sql = """
- select t1.city_name, t2.level, t2.region_id from ctop_kuaishou_city_level t1
- left join ctop_kuaishou_region_list_parent t2
- on t1.city_name = t2.name
- where t1.city_level in %s
- """ % (tuple(val1.split('|')),)
- city_df = pd.read_sql(sql, None)
- # level1
- if city_df[city_df.level == 1].region_id.values in eval(val2):
- val.extend(city_df[city_df.level == 1].region_id.values)
- else:
- return False, -1
- # level2
- while not is_contains:
- pass
- # level3
- pass
- def is_contains_gender(val1, val2):
- """
- :param val1: ctop_ai_kuaishou_signature_recommended_target_combine 中的 gender 字段: '男'、'女'、'不限'、None
- :param val2: ctop_ai_kuaishou_advertiser_strategy 中的 gender 字段: 1:女性, 2:男性,0表示不限
- :return: val1 是否为 val2的子集,以及传递给快手后台的值
- """
- is_contains = False
- val = None
- if val1 == '男' and val2 in (2, 0):
- is_contains = True
- val = val1
- if val1 == '女' and val2 in (1, 0):
- is_contains = True
- val = val1
- if val1 == '不限' and val2 == 0:
- is_contains = True
- val = val2
- # 如果val1为空,表示该字段没有参与定向组合运算,就直接取客户投放策略里面的值
- if val1 is None:
- is_contains = True
- val = val2
- return is_contains, {'gender': val}
- def is_contains_platform_os(val1, val2):
- """
- :param val1: ctop_ai_kuaishou_signature_recommended_target_combine 中的 client 字段: '男'、'女'、'不限'、None
- :param val2:
- :return:
- """
- pass
- def is_contains_age(val1, val2):
- pass
- def is_contains_business_interest(val1, val2):
- pass
|