def __init__(self): self.time_now = datetime.datetime.now() self.code_name = {'ts-1796606':'省油宝', 'ts-1797607':'选词王', 'ts-1817244':'淘词'} self.order_type = {1:'新订', 2:'续订', 3:'升级', 4:'后台赠送', 5:'后台自动续订'} self.support_type = {7:'7天初访', 14:'2周回访', 30:'1月回访', 90:'3月回访', \ 180:'半年回访',270:'9月回访',-3:'3天到期续签'} self.time_type = {u'1个月':[7,14,-3],\ u'3个月':[7,30,-3],\ u'6个月':[7,30,90,-3],\ u'12个月':[7,30,180,270,-3]} logger.info('UserCenter init success')
def daily_update_script(): """更新user_center 并将更新导入到百会CRM""" logger.info('user_center update start') try: user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_update_info() user_obj.write_baihui_info() user_obj.update_online() except Exception, e: logger.exception('user_center update error: %s', str(e)) send_sms('13738141586', 'user_center update error: ' + str(e))
def daily_update_script(): """更新user_center 并将更新导入到百会CRM""" logger.info('user_center update start') try: user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_update_info() user_obj.write_baihui_info() user_obj.update_online() except Exception,e: logger.exception('user_center update error: %s', str(e)) send_sms('13738141586', 'user_center update error: '+str(e))
def collect_update_worker(self): """更新客户客服关系""" for nick in self.nick_worker.keys(): new_worker_id = self.nick_worker[nick] shop = self.nick_shop.get(nick, None) if not shop: #要更新的用户 并不存在 logger.info('collect_update_worker %s not exist' % nick) print 'collect_update_worker %s not exist' % nick continue if shop['worker_id'] != new_worker_id: shop['worker_id'] = new_worker_id shop['update_time'] = self.time_now self.update_shops.append(shop) for article_code in self.code_name.keys(): key = nick + article_code order = self.user_order.get(key, None) if order: self.add_orders.append(order)
def collect_update_worker(self): """更新客户客服关系""" for nick in self.nick_worker.keys(): new_worker_id = self.nick_worker[nick] shop = self.nick_shop.get(nick, None) if not shop: #要更新的用户 并不存在 logger.info('collect_update_worker %s not exist' % nick) print 'collect_update_worker %s not exist' % nick continue if shop['worker_id'] != new_worker_id: shop['worker_id'] = new_worker_id shop['update_time'] = self.time_now self.update_shops.append(shop) for article_code in self.code_name.keys(): key = nick+article_code order = self.user_order.get(key, None) if order: self.add_orders.append(order)
import DataMonitor.conf.settings from CommonTools.send_tools import send_sms from CommonTools.logger import logger from DataMonitor.monitor.monitor_marketing_cost import monitor_marketing_cost from DataMonitor.monitor.monitor_order_add import monitor_order_add from DataMonitor.monitor.monitor_comment_add import monitor_comment_add def monitor_soft_script(): try: return_info = monitor_soft() except Exception,e: logger.exception('monitor_soft error: %s', str(e)) send_sms('13738141586', 'monitor_soft_script error: '+str(e)) else: logger.info(return_info) def monitor_soft(): """软件监测脚本 1.麦苗科技营销花费 定期监测 2.省油宝新增订单数 定期监测 3.省油宝新增评价 定期监测 4.北斗新增评价 定期监测 省油宝,ts-1796606 北斗,ts-1797607 """ current_time = datetime.datetime.now() rest_hours = range(1,7) if current_time.hour in rest_hours: return None
content = '' content += analysis_campaign_complex(syb_file, '省油宝长尾计划') content += analysis_campaign_complex(syb_file, '省油宝加力计划') content += analysis_campaign_complex(bd_file, '北斗专属计划') content += analysis_campaign_simple(syb_file) content += analysis_campaign_horizontal(syb_file) return content def analysis_campaign_script(): today = str(datetime.date.today()) syb_file = CURRENT_DIR+'data/report_data/syb_report' + today + '.csv' bd_file = CURRENT_DIR+'data/report_data/bd_report' + today + '.csv' if not os.path.exists(syb_file): logger.error('analysis_campaign error: %s not exists ' % (syb_file)) return None try: content = analysis_campaign(syb_file, bd_file) #send_email_with_text('*****@*****.**', content, today+'_产品报表日常分析') send_email_with_text('*****@*****.**', content, today+'_产品报表日常分析') except Exception,e: logger.exception('analysis_campaign error: %s' % (str(e))) send_sms('13738141586', 'analysis_campaign error: %s' % (str(e))) else: logger.info('analysis_campaign ok') if __name__ == '__main__': analysis_campaign_script() #print analysis_campaign('/home/zhoujiebing/Analysis/DataAnalysis/data/report_data/report2013-04-17.csv')
for order in page_list: if order['payTime'].find(today) != -1: order_nick = order['nick'] if order_nick.find('<font title="') != -1: order_nick = order_nick.split('"') order['nick'] = order_nick[1] order_list.append(order) flag = True if not flag and order['payTime'].find(str(self.yesterday)) != -1: break return order_list def collect_order_script(_days=0): today = datetime.date.today() - datetime.timedelta(days=_days) try: ztc = ZtcOrderCollect(today) ztc.get_order() ztc.write_order() except Exception,e: logger.error('collect_order_script %s: %s' % (str(today), str(e))) send_sms('13738141586', 'collect_order_script %s: %s' % (str(today), str(e))) else: logger.info('collect_order_script %s ok', str(today)) if __name__ == '__main__': if len(sys.argv) == 1: collect_order_script() else: collect_order_script(int(sys.argv[1]))
def collect_online_info(self): """获取用户数据中心信息""" logger.info('start collect_online_info') #获取所有用户 all_shop = ShopDBService.get_all_shop_list() self.nick_shop = {} for shop in all_shop: self.nick_shop[shop['nick']] = shop logger.info('finish collect shop info') #获取所有订单 all_order = OrderDBService.get_all_orders_list() logger.info('finish collect order info') self.user_orders = {} for order in all_order: key = (order['nick'], order['article_code']) if not self.user_orders.has_key(key): self.user_orders[key] = [] self.user_orders[key].append(order) logger.info('finish arrange order info') #获取所有退款 all_refund = RefundDBService.get_all_refunds_list() refund_list = [refund['order_id'] for refund in all_refund] logger.info('finish collect refund info') for key in self.user_orders.keys(): real_orders = [] orders = self.user_orders[key] orders.sort(key=lambda order:order['order_cycle_start']) for i in range(len(orders)): order = orders[i] if int(order['total_pay_fee']) > 500: if i < len(orders) - 1: next_order = orders[i+1] if int(next_order['total_pay_fee']) <= 500 and next_order['biz_type'] == 2: order['order_cycle_end'] = next_order['order_cycle_end'] real_orders.append(order) self.user_orders[key] = real_orders logger.info('finish collect_online_info')
def collect_update_info(self): """收集更新""" for shop in self.nick_shop.values(): worker_id = shop.get('worker_id', None) if not worker_id: logger.info('%s worker_id 为 none' % (shop['nick'])) print '%s worker_id 为 none' % (shop['nick']) continue upset_flag = False normal_flag = False for article_code in self.code_name.keys(): key = shop['nick'] + article_code article_status = article_code + '_status' article_order = article_code + '_order_id' article_deadline = article_code + '_deadline' #获取shop中关于该产品的信息 deadline = shop.get(article_deadline, None) order = self.user_order.get(key, None) order_id = shop.get(article_order, None) supports = self.user_supports.get(key, []) if not order and order_id: #新退款用户 shop[article_order] = None shop[article_status] = '退款' shop[article_code + '_deadline'] = None upset_flag = True if order and order_id != order['order_id']: #新订或续订用户 deadline = order['order_cycle_end'] shop[article_code + '_deadline'] = deadline shop[article_order] = order['order_id'] upset_flag = True #百会导入 self.add_orders.append(order) if not deadline: #压根没购买过 continue if deadline < self.time_now and shop[article_status] == '使用中': shop[article_status] = '到期' upset_flag = True if deadline > self.time_now: #至少有一个产品是有效的 normal_flag = True #以下是服务支持部分 for support in supports: if support['order_id'] != shop[article_order] and \ support['support_status'] == '未处理': support['support_status'] = '无效' self.update_supports.append(support) if order and order_id != order['order_id']: #新订或续订用户 self.update_supports.extend( self.generate_order_supports(order)) if not normal_flag and shop['flag']: #没有一个有效的产品 转变为无效用户 shop['flag'] = False upset_flag = True #收集待更新的用户数据 if upset_flag: shop['update_time'] = self.time_now self.update_shops.append(shop)
def daily_update_script(): """更新user_center 并将更新导入到百会CRM""" logger.info('user_center update start') try: user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_update_info() user_obj.write_baihui_info() user_obj.update_online() except Exception, e: logger.exception('user_center update error: %s', str(e)) send_sms('13738141586', 'user_center update error: ' + str(e)) else: logger.info('user_center update finish') def reset_useful_support_script(): """全量更新服务支持""" user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_reset_supports() user_obj.update_online() def reset_user_worker_relation(): """重设部分客户客服关系""" user_obj = UserCenter(['ts-1796606'])
def collect_update_info(self): """收集更新""" for shop in self.nick_shop.values(): worker_id = shop.get('worker_id', None) if not worker_id: logger.info('%s worker_id 为 none' % (shop['nick'])) print '%s worker_id 为 none' % (shop['nick']) continue upset_flag = False normal_flag = False for article_code in self.code_name.keys(): key = shop['nick'] + article_code article_status = article_code + '_status' article_order = article_code + '_order_id' article_deadline = article_code + '_deadline' #获取shop中关于该产品的信息 deadline = shop.get(article_deadline, None) order = self.user_order.get(key, None) order_id = shop.get(article_order, None) supports = self.user_supports.get(key, []) if not order and order_id: #新退款用户 shop[article_order] = None shop[article_status] = '退款' shop[article_code + '_deadline'] = None upset_flag = True if order and order_id != order['order_id']: #新订或续订用户 deadline = order['order_cycle_end'] shop[article_code + '_deadline'] = deadline shop[article_order] = order['order_id'] upset_flag = True #百会导入 self.add_orders.append(order) if not deadline: #压根没购买过 continue if deadline < self.time_now and shop[article_status] == '使用中': shop[article_status] = '到期' upset_flag = True if deadline > self.time_now: #至少有一个产品是有效的 normal_flag = True #以下是服务支持部分 for support in supports: if support['order_id'] != shop[article_order] and \ support['support_status'] == '未处理': support['support_status'] = '无效' self.update_supports.append(support) if order and order_id != order['order_id']: #新订或续订用户 self.update_supports.extend(self.generate_order_supports(order)) if not normal_flag and shop['flag']: #没有一个有效的产品 转变为无效用户 shop['flag'] = False upset_flag = True #收集待更新的用户数据 if upset_flag: shop['update_time'] = self.time_now self.update_shops.append(shop)
file_obj.close() def daily_update_script(): """更新user_center 并将更新导入到百会CRM""" logger.info('user_center update start') try: user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_update_info() user_obj.write_baihui_info() user_obj.update_online() except Exception,e: logger.exception('user_center update error: %s', str(e)) send_sms('13738141586', 'user_center update error: '+str(e)) else: logger.info('user_center update finish') def reset_useful_support_script(): """全量更新服务支持""" user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_reset_supports() user_obj.update_online() def reset_user_worker_relation(): """重设部分客户客服关系""" user_obj = UserCenter(['ts-1796606']) user_obj.collect_online_info() user_obj.collect_update_worker()
type_num = {} for key in ORDER_TYPE: type_num[key] = 0 order_list = self.order_dict[id_name] for order in order_list: if not type_num.has_key(order['deadline']): type_num['其他'] += 1 else: type_num[order['deadline']] += 1 return type_num def analysis_ztc_order_script(): ToMe = '*****@*****.**' ToAll = '*****@*****.**' try: ztc = ZtcOrderReport() ztc.make_report() ztc.write_report() html = ztc.getHtml() #send_email_with_html(ToMe, html, str(datetime.date.today())+'__直通车软件报表内侧版') send_email_with_html(ToAll, html, str(datetime.date.today())+'__直通车软件报表公测版') except Exception,e: logger.exception('analysis_ztc_order_script error: %s' % (str(e))) send_sms('13738141586', 'analysis_ztc_order_script error: '+str(e)) else: logger.info('analysis_ztc_order_script ok') if __name__ == '__main__': analysis_ztc_order_script()
import DataMonitor.conf.settings from CommonTools.send_tools import send_sms from CommonTools.logger import logger from DataMonitor.monitor.monitor_marketing_cost import monitor_marketing_cost from DataMonitor.monitor.monitor_order_add import monitor_order_add from DataMonitor.monitor.monitor_comment_add import monitor_comment_add def monitor_soft_script(): try: return_info = monitor_soft() except Exception, e: logger.exception('monitor_soft error: %s', str(e)) send_sms('13738141586', 'monitor_soft_script error: ' + str(e)) else: logger.info(return_info) def monitor_soft(): """软件监测脚本 1.麦苗科技营销花费 定期监测 2.省油宝新增订单数 定期监测 3.省油宝新增评价 定期监测 4.北斗新增评价 定期监测 省油宝,ts-1796606 北斗,ts-1797607 """ current_time = datetime.datetime.now() rest_hours = range(1, 7) if current_time.hour in rest_hours: return None