浏览代码

消耗添加跑上个月的

ck 4 年之前
父节点
当前提交
2e10e78b6d
共有 2 个文件被更改,包括 28 次插入5 次删除
  1. 19 5
      dgp/tests/get_data_hourly.py
  2. 9 0
      dgp/tests/util/date_util.py

+ 19 - 5
dgp/tests/get_data_hourly.py

@@ -18,10 +18,10 @@ import random
 import token_list as tl
 import smtplib
 from email.mime.text import MIMEText
-from datetime import datetime,timedelta
+from datetime import datetime,timedelta,date
 from concurrent.futures import ThreadPoolExecutor
 from datetime import datetime
-
+from util import date_util
 
 def md5value(s):
 	md5 = hashlib.md5()
@@ -178,9 +178,23 @@ if __name__ == '__main__':
 	my_time = datetime.today().strftime('%Y-%m-%d')
 	# my_time = '2020-11-24'
 	if sys.argv.__len__() == 2:
-		yestoday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
-		my_time = yestoday
-		print("跑昨天[" + yestoday + "]数据")
+		if sys.argv[1]=='month':
+			fday,lday=date_util.getLastMonthDay()
+			i=0
+			my_time = fday.strftime("'%Y-%m-%d'")
+			while True:
+				my_time=(fday+timedelta(days=i)).strftime("%Y-%m-%d")
+				print(my_time)
+				start_cost_job()
+				if my_time==lday.strftime("%Y-%m-%d"):
+					exit(0)
+				else:
+					i+=1
+
+		else:
+			yestoday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
+			my_time = yestoday
+			print("跑昨天[" + yestoday + "]数据")
 
 	start_cost_job()
 

+ 9 - 0
dgp/tests/util/date_util.py

@@ -32,6 +32,15 @@ import time
 # ========== time ==========
 # ==========================
 
+def getLastMonthDay():
+    """
+    获取上月第一天和最后一天
+    @returen  str"""
+    today = datetime.date.today()
+    last_day_of_last_month = datetime.date(today.year, today.month, 1) - datetime.timedelta(1)
+    first_day_of_last_month = datetime.date(last_day_of_last_month.year, last_day_of_last_month.month, 1)
+    return first_day_of_last_month, last_day_of_last_month
+
 
 def getCurrentMilliSecondTime():
     """