Browse Source

时间获取方法修改逻辑

Signed-off-by: Binren Zhnag <zhangbr@elab-plus.com>
Binren Zhnag 4 years ago
parent
commit
a3131144ce
3 changed files with 25 additions and 21 deletions
  1. 19 17
      jianye_report.py
  2. 1 1
      report_file_utils.py
  3. 5 3
      report_public_funs_utils.py

+ 19 - 17
jianye_report.py

@@ -269,6 +269,7 @@ class JianYeReport(object):
                     message[111] = '项目'
                     table_2 = self.house_data(self.get_house_ids(ids))
                     message[222] = 'house_data'
+                    message[99999] = table_2
                     rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], save_path)
                 elif customer_type == 3:
                     # 区域
@@ -278,24 +279,25 @@ class JianYeReport(object):
                     rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], save_path)
                 else:
                     pass
-                send_mail_info.append([title, content, mail, file_path, title + '.xlsx'])
+                send_mail_info.append([title, content, mail, file_path, title + '.xlsx', name])
                 message[1] = '数据查询和excel生成完毕'
-                # 发送邮件
-                send_mail_log = []
-                for mail in send_mail_info:
-                    try:
-                        for m in self.customer_mails:
-                            result = mail_util.send_mail_by_admin(mail[0], mail[1], m, mail[3], mail[4])
-                            if result:
-                                # name, mail, report_name, push_time, send_status, status, error_message
-                                send_mail_log.append([name, mail[2], mail[3], 1, 'success'])
-                            else:
-                                send_mail_log.append([name, mail[2], mail[3], -1, 'fail'])
-                    except Exception as e:
-                        print(str(e))
-                        send_mail_log.append([name, mail[2], mail[3], -1, str(e)])
-                self.db.add_some(send_mail_info, Sql.sql_12)
-                message[2] = '遇见发送完毕, 共:{}份邮件'.format(len(send_mail_info))
+                break
+            # 发送邮件
+            send_mail_log = []
+            for mail in send_mail_info:
+                try:
+                    for m in self.customer_mails:
+                        result = mail_util.send_mail_by_admin(mail[0], mail[1], m, mail[3], mail[4])
+                        if result:
+                            # name, mail, report_name, push_time, send_status, status, error_message
+                            send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
+                        else:
+                            send_mail_log.append([mail[5], mail[2], mail[3], -1, 'fail'])
+                except Exception as e:
+                    print(str(e))
+                    send_mail_log.append([mail[5], mail[2], mail[3], -1, str(e)])
+            self.db.add_some(send_mail_info, Sql.sql_12)
+            message[2] = '遇见发送完毕, 共:{}份邮件'.format(len(send_mail_info))
         except Exception as e:
             message['error'] = str(e)
         finally:

+ 1 - 1
report_file_utils.py

@@ -3,7 +3,6 @@ import xlwt
 
 class ReportFileUtils:
     def __init__(self):
-        self.wb = xlwt.Workbook()
         self.styleOK = xlwt.easyxf()
         self.default_style = self.set_style('Times New Roman',
                        200,
@@ -123,6 +122,7 @@ class ReportFileUtils:
         :param headers: 每个工作簿表头
         :return:
         """
+        self.wb = xlwt.Workbook()
         for index, d in enumerate(data):
             # 创建工作簿
             sheet_name = sheet_names[index]

+ 5 - 3
report_public_funs_utils.py

@@ -10,8 +10,10 @@ class ReportPublicFunsUtils:
         :return:
         """
         now_time = datetime.datetime.now()
-        first_day_of_month = datetime.datetime.now().strftime('%Y-%M')
-        if not type:
+        year = now_time.year
+        month = now_time.month
+        first_day_of_month = str(year) + '-' + str(month)
+        if type:
             return [first_day_of_month + '-01 00:00:00', now_time.strftime('%Y-%m-%d %M:%I:%S')]
         else:
             return [first_day_of_month + '-01', now_time.strftime('%Y-%m-%d')]
@@ -60,4 +62,4 @@ class ReportPublicFunsUtils:
 
 
 if __name__ == '__main__':
-    print(ReportPublicFunsUtils.get_montho_day())
+    print(ReportPublicFunsUtils.get_time_range_month())