Exemple #1
0
 def compute_flow(self):
     if is_time_early():
         first_range = {
             'from': get_upper_first(),
             'to': get_yesterday_time()
         }
         last_range = {'from': get_upper_first(), 'to': get_today_time()}
     else:
         first_range = {
             'from': get_early_time(),
             'to': get_yesterday_time()
         }
         last_range = {'from': get_early_time(), 'to': get_today_time()}
     try:
         first_response = self.get_bw(first_range)
         last_response = self.get_bw(last_range)
         customer = self.get_customer()
         libs = self.get_libs()
         dispose = LumDispose(customer, libs)
         first_bw = dispose.dispose_flow(first_response, first_range)
         last_bw = dispose.dispose_flow(last_response, last_range)
         self.make_flow_report(first_bw)
         compute_bw = {}
         for item in first_bw['zones']:
             compute_bw[item] = \
                 self.conversion(self.get_value(last_bw['zones'][item]) - self.get_value(first_bw['zones'][item]))
         self.submit(compute_bw)
     except:
         if IS_FAIL:
             mail = Mail()
             mail.send_content_mail(FAIL_MSG2 % 'compute_flow',
                                    FAIL_TITLE_MSG, MAIL_FLOW_SEND)
             # mail.send_content_mail(FAIL_MSG % 'compute_flow', FAIL_TITLE_MSG, MAIL_TEST)
             mail.close()
     return schedule.CancelJob
Exemple #2
0
 def query_balance(self):
     range = {'from': get_early_time2(), 'to': get_today_time2()}
     bw_range = {'from': get_early_time(), 'to': get_today_time()}
     try:
         bw = self.get_bw(bw_range)
         customer = self.get_customer()
         libs = self.get_libs()
         billing = self.get_billing()
         dispose = LumDispose(customer, libs)
         balance = dispose.dispose_balance(bw, billing, range)
         if balance['calc_balance'] < 50:
             mail = Mail()
             mail.send_content_mail(FLOW_MSG % balance['calc_balance'],
                                    '余额不足', MAIL_BALANCE_SEND)
             mail.close()
     except:
         if IS_FAIL:
             mail = Mail()
             mail.send_content_mail(FAIL_MSG % 'query_balance',
                                    FAIL_TITLE_MSG, MAIL_TEST)
             mail.close()
Exemple #3
0
 def submit(self, data):
     bw, bw_success, bw_fail, num_success, num_fail = '%s : %s/g, ', '', '', 0, 0
     for item in data:
         API_PARAM['zone'] = item
         API_PARAM['use_flow'] = data[item]
         # self.request.post_back_data(GEEK_API, API_PARAM)
         try:
             response = self.request.post_back_data(QUICKBUY_API, API_PARAM)
             if response.status_code == 200:
                 bw_success += bw % (item, data[item])
                 num_success += 1
             else:
                 bw_fail += bw % (item, data[item])
                 num_fail += 1
         except:
             bw_fail += bw % (item, data[item])
             num_fail += 1
             continue
     mail = Mail()
     mail.send_content_mail(
         SUCCESS_MSG % (bw_success, num_success, bw_fail, num_fail),
         SUCCESS_TITLE_MSG, MAIL_FLOW_SEND)
     mail.close()
Exemple #4
0
def test():
    mail = Mail()
    mail.send_content_mail('你好世界', '测试', MAIL_TEST)
    # path = 'C:\\Users\\27390\\Desktop\\agent-reptile\\export\\Flow_2019_02_01_2019_03_28.csv'
    # mail.send_file_mail('上个月的流量报表', '流量报表', path, MAIL_TEST)
    mail.close()