class NginxCoupon(object): def __init__(self, cf): self.act_id = cf.getint('coupon', 'act_id') self.page_size = cf.getint('online_db', 'page_size') self.date_period = [cf.getint('coupon', 'start_date'), cf.getint('coupon', 'end_date')] conf = dict() conf['host'] = cf.get('online_db', 'host') conf['user'] = cf.get('online_db', 'user') conf['passwd'] = cf.get('online_db', 'passwd') conf['name'] = cf.get('online_db', 'name') conf['port'] = cf.getint('online_db', 'port') conf['charset'] = cf.get('online_db', 'charset') self.dao = MysqlDao(conf) self.hits_conf = dict() self.hits_conf[30] = cf.getfloat('coupon', 'hits_30') self.hits_conf[50] = cf.getfloat('coupon', 'hits_50') self.hits_conf[100] = cf.getfloat('coupon', 'hits_100') self.hits_conf[300] = cf.getfloat('coupon', 'hits_300') self.hits_conf[500] = cf.getfloat('coupon', 'hits_500') def run(self): start = 0 user_hits = self.dao.select_hits_by_actid(self.act_id, start, self.page_size) unique_key = ['user_id', 'act_id'] hits_key = self.hits_conf.keys() hits_key.sort() user_totle = 0 while user_hits: user_totle += len(user_hits) for e in user_hits: if e['hits'] < hits_key[0]: continue db_dict = dict() db_dict['user_id'] = e['user_id'] db_dict['act_id'] = self.act_id db_dict['effective_date'] = self.date_period[0] db_dict['expiry_date'] = self.date_period[1] db_dict['status'] = 0 db_dict['is_deleted'] = 'N' index = -1 for k in hits_key[::-1]: if e['hits'] >= k: break index -= 1 db_dict['face_value'] = self.hits_conf[hits_key[index]] self.dao.insert_or_update_template('db_hd_coupon', db_dict, unique_key) start += self.page_size user_hits = self.dao.select_hits_by_actid(self.act_id, start, self.page_size) print '插入用户优惠劵条目: %d 张' % user_totle
def __init__(self, cf): self.act_id = cf.getint('coupon', 'act_id') self.page_size = cf.getint('online_db', 'page_size') self.date_period = [cf.getint('coupon', 'start_date'), cf.getint('coupon', 'end_date')] conf = dict() conf['host'] = cf.get('online_db', 'host') conf['user'] = cf.get('online_db', 'user') conf['passwd'] = cf.get('online_db', 'passwd') conf['name'] = cf.get('online_db', 'name') conf['port'] = cf.getint('online_db', 'port') conf['charset'] = cf.get('online_db', 'charset') self.dao = MysqlDao(conf) self.hits_conf = dict() self.hits_conf[30] = cf.getfloat('coupon', 'hits_30') self.hits_conf[50] = cf.getfloat('coupon', 'hits_50') self.hits_conf[100] = cf.getfloat('coupon', 'hits_100') self.hits_conf[300] = cf.getfloat('coupon', 'hits_300') self.hits_conf[500] = cf.getfloat('coupon', 'hits_500')
def __init__(self, cf): conf = dict() conf['host'] = cf.get('online_db', 'host') conf['user'] = cf.get('online_db', 'user') conf['passwd'] = cf.get('online_db', 'passwd') conf['name'] = cf.get('online_db', 'name') conf['port'] = cf.getint('online_db', 'port') conf['charset'] = cf.get('online_db', 'charset') self.shop_dao = MysqlDao(conf) conf['host'] = cf.get('online_db', 'sea_host') conf['user'] = cf.get('online_db', 'sea_user') conf['passwd'] = cf.get('online_db', 'sea_passwd') conf['name'] = cf.get('online_db', 'sea_name') conf['port'] = cf.getint('online_db', 'sea_port') conf['charset'] = cf.get('online_db', 'sea_charset') self.sea_dao = MysqlDao(conf) self.page_size = cf.getint('online_db', 'page_size')
def stat_result(self): conf = dict() conf['host'] = self.cf.get('online_db', 'host') conf['user'] = self.cf.get('online_db', 'user') conf['passwd'] = self.cf.get('online_db', 'passwd') conf['name'] = self.cf.get('online_db', 'name') conf['charset'] = self.cf.get('online_db', 'charset') conf['port'] = self.cf.getint('online_db', 'port') dao = MysqlDao(conf) unique_key = ['user_id', 'act_id'] for user_id, hits in self.user_hits.items(): db_dict = dict() db_dict['user_id'] = user_id db_dict['act_id'] = self.act_id db_dict['hits'] = hits db_dict['is_deleted'] = 'N' dao.insert_or_update_template('db_hd_share_hits', db_dict, unique_key) print '统计nginx log得到%d位用户的点击量' % len(self.user_hits)
class GoodsFix: def __init__(self, cf): conf = dict() conf['host'] = cf.get('online_db', 'host') conf['user'] = cf.get('online_db', 'user') conf['passwd'] = cf.get('online_db', 'passwd') conf['name'] = cf.get('online_db', 'name') conf['port'] = cf.getint('online_db', 'port') conf['charset'] = cf.get('online_db', 'charset') self.shop_dao = MysqlDao(conf) conf['host'] = cf.get('online_db', 'sea_host') conf['user'] = cf.get('online_db', 'sea_user') conf['passwd'] = cf.get('online_db', 'sea_passwd') conf['name'] = cf.get('online_db', 'sea_name') conf['port'] = cf.getint('online_db', 'sea_port') conf['charset'] = cf.get('online_db', 'sea_charset') self.sea_dao = MysqlDao(conf) self.page_size = cf.getint('online_db', 'page_size') def seller_goods_fix(self): all_goods_id = self.shop_dao.select_goods_id_by_seller(2000) insert_goods_id = all_goods_id.difference( self.sea_dao.select_goods_rel(all_goods_id)) goods_rel = [] for e in self.shop_dao.select_goods_info(insert_goods_id): db_dict = dict() db_dict['seller_id'] = 2000 db_dict['goods_id'] = e['goods_id'] db_dict['goods_sn'] = e['new_goods_sn'] db_dict['seller_goods_name'] = e['goods_name'] db_dict['seller_goods_sn'] = e['attr_value'] db_dict['seller_unit'] = e['measure_unit'] db_dict['seller_valid'] = 1 db_dict['status'] = 1 db_dict['is_deleted'] = 'N' goods_rel.append(db_dict) if len(goods_rel) > self.page_size: self.sea_dao.insert_batch('sea_goods_rel', goods_rel) goods_rel = [] if len(goods_rel) > 0: self.sea_dao.insert_batch('sea_goods_rel', goods_rel)
class GoodsFix: def __init__(self, cf): conf = dict() conf['host'] = cf.get('online_db', 'host') conf['user'] = cf.get('online_db', 'user') conf['passwd'] = cf.get('online_db', 'passwd') conf['name'] = cf.get('online_db', 'name') conf['port'] = cf.getint('online_db', 'port') conf['charset'] = cf.get('online_db', 'charset') self.shop_dao = MysqlDao(conf) conf['host'] = cf.get('online_db', 'sea_host') conf['user'] = cf.get('online_db', 'sea_user') conf['passwd'] = cf.get('online_db', 'sea_passwd') conf['name'] = cf.get('online_db', 'sea_name') conf['port'] = cf.getint('online_db', 'sea_port') conf['charset'] = cf.get('online_db', 'sea_charset') self.sea_dao = MysqlDao(conf) self.page_size = cf.getint('online_db', 'page_size') def seller_goods_fix(self): all_goods_id = self.shop_dao.select_goods_id_by_seller(2000) insert_goods_id = all_goods_id.difference(self.sea_dao.select_goods_rel(all_goods_id)) goods_rel = [] for e in self.shop_dao.select_goods_info(insert_goods_id): db_dict = dict() db_dict['seller_id'] = 2000 db_dict['goods_id'] = e['goods_id'] db_dict['goods_sn'] = e['new_goods_sn'] db_dict['seller_goods_name'] = e['goods_name'] db_dict['seller_goods_sn'] = e['attr_value'] db_dict['seller_unit'] = e['measure_unit'] db_dict['seller_valid'] = 1 db_dict['status'] = 1 db_dict['is_deleted'] = 'N' goods_rel.append(db_dict) if len(goods_rel) > self.page_size: self.sea_dao.insert_batch('sea_goods_rel', goods_rel) goods_rel = [] if len(goods_rel) > 0: self.sea_dao.insert_batch('sea_goods_rel', goods_rel)