ck 4 năm trước cách đây
mục cha
commit
607c208a1f
2 tập tin đã thay đổi với 26 bổ sung9 xóa
  1. 1 0
      app/api_data/order_util.py
  2. 25 9
      model/DateUtils.py

+ 1 - 0
app/api_data/order_util.py

@@ -101,6 +101,7 @@ def parse_yg_data(vip_id,stage):
         date = DateUtils.str_to_stamp(order_time[:10])
         insert_data.append((date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id))
     # print(insert_data)
+    print("订单数:"+ str(insert_data.__len__()))
     db.quchen_text.executeMany("replace into `order`(date,stage,platform,channel,channel_id,"
                            "user_id,order_time,reg_time,amount,from_novel,order_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",tuple(insert_data))
 

+ 25 - 9
model/DateUtils.py

@@ -14,6 +14,29 @@ class DateUtils:
         self.daydelta = timedelta(days=1)
         self.now = datetime.now()
 
+
+    def add_days(self,str, interval):
+        return (datetime.strptime(str,'%Y-%m-%d')+timedelta(days=interval)).strftime('%Y-%m-%d')
+
+
+    def split_date(self,start, end, interval, func):
+        """把时间拆分多次运行"""
+        st = start
+        et = self.add_days(st, interval - 1)
+
+        while True:
+            if et >= end:
+                et = end
+                print(f"{st}~{et}")
+                func(st, et)
+                break
+            else:
+                print(f"{st}~{et}")
+                func(st,et)
+                st=self.add_days(et, 1)
+                et=self.add_days(st, interval - 1)
+
+
     def getDateLists(self, begin, end):
         """
         返回一个时间列表
@@ -283,12 +306,5 @@ class DateUtils:
 
 if __name__ == "__main__":
     ut = DateUtils()
-    end = ut.now.strftime('%Y-%m') + '-01 00:00:00'
-    # begin = ut.get_n_month_ago_begin(ut.now.strftime('%Y-%m'), 1) + '-01 00:00:00'
-    # print(ut.get_n_pre_month_first_day(0))
-    # ut.today = date(2018, 1, 1)
-    # print(ut.month_first_day())
-    # a='2021-01-01 00:01:01'
-    # b=datetime.strptime(a,'%Y-%m-%d %H:%M:%S')
-    # print(b.hour)
-    # print(ut.now.hour)
+    # end = ut.now.strftime('%Y-%m') + '-01 00:00:00'
+