Ver Fonte

增加测试代码

zhengwangeng há 4 anos atrás
pai
commit
f78dd1a9a3
5 ficheiros alterados com 146 adições e 47 exclusões
  1. 2 2
      README.md
  2. 0 22
      dgp/__init__.py
  3. 0 23
      dgp/tests/__init__.py
  4. 71 0
      dgp/tests/logger.py
  5. 73 0
      dgp/tests/test.py

+ 2 - 2
README.md

@@ -23,8 +23,8 @@ Data grabbing platform(DGP)数据采集平台
 #### 参与贡献
 
 * Fork 本仓库,拉取的是dev分支
-* 直接在dev分支上开发,添加新的依赖后请执行 `pip freeze > requirements.txt` 或 `pipreqs /qc-dgp`
-* 提交代码
+* 直接在dev分支上开发,添加新的依赖后请执行 `pip freeze > requirements.txt` 或 `pipreqs --force /qc-dgp`
+* 格式化代码,提交代码
 * 新建 Pull Request
 
 

+ 0 - 22
dgp/__init__.py

@@ -1,22 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-__title__ = 'Package_name' __author__ = '
-Package_name' __author__ = '
-USER'
-__mtime__ = '2020/9/24'
-# code is far away from bugs with the god animal protecting
-    I love animals. They taste delicious.
-              ┏┓      ┏┓
-            ┏┛┻━━━┛┻┓
-            ┃      ☃      ┃
-            ┃  ┳┛  ┗┳  ┃
-            ┃      ┻      ┃
-            ┗━┓      ┏━┛
-                ┃      ┗━━━┓
-                ┃  神兽保佑    ┣┓
-                ┃ 永无BUG!   ┏┛
-                ┗┓┓┏━┳┓┏┛
-                  ┃┫┫  ┃┫┫
-                  ┗┻┛  ┗┻┛
-"""

+ 0 - 23
dgp/tests/__init__.py

@@ -1,23 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-__title__ = 'Package_name' __author__ = '
-Package_name' __author__ = '
-USER'
-__mtime__ = '2020/9/24'
-# code is far away from bugs with the god animal protecting
-    I love animals. They taste delicious.
-              ┏┓      ┏┓
-            ┏┛┻━━━┛┻┓
-            ┃      ☃      ┃
-            ┃  ┳┛  ┗┳  ┃
-            ┃      ┻      ┃
-            ┗━┓      ┏━┛
-                ┃      ┗━━━┓
-                ┃  神兽保佑    ┣┓
-                ┃ 永无BUG!   ┏┛
-                ┗┓┓┏━┳┓┏┛
-                  ┃┫┫  ┃┫┫
-                  ┗┻┛  ┗┻┛
-"""
-

+ 71 - 0
dgp/tests/logger.py

@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+@Time    : 2020/9/25 13:36
+@Author  : zhengwangeng
+@Software: PyCharm
+
+# code is far away from bugs with the god animal protecting
+    I love animals. They taste delicious.
+              ┏┓      ┏┓
+            ┏┛┻━━━┛┻┓
+            ┃      ☃      ┃
+            ┃  ┳┛  ┗┳  ┃
+            ┃      ┻      ┃
+            ┗━┓      ┏━┛
+                ┃      ┗━━━┓
+                ┃  神兽保佑    ┣┓
+                ┃ 永无BUG!   ┏┛
+                ┗┓┓┏━┳┓┏┛
+                  ┃┫┫  ┃┫┫
+                  ┗┻┛  ┗┻┛
+"""
+
+import logging
+import sys
+
+from logging.handlers import TimedRotatingFileHandler
+
+
+class LoggerService:
+
+	@staticmethod
+	def logger_timefile(log_file, log_name, backupCount=10):
+		logger = logging.getLogger(log_name)
+		logger.setLevel(logging.DEBUG)
+		# format
+		formatter = logging.Formatter(fmt='%(asctime)s - %(filename)s[%(lineno)d] - %(levelname)s - %(message)s',
+									  datefmt='%Y/%m/%d %H:%M:%S')
+
+		# StreamHandler
+		stream_handler = logging.StreamHandler(sys.stdout)
+		stream_handler.setFormatter(formatter)
+		logger.addHandler(stream_handler)
+
+		# 创建TimedRotatingFileHandler对象
+		file_handler2 = TimedRotatingFileHandler(filename=log_file, when="D", interval=1, backupCount=backupCount)
+		file_handler2.setFormatter(formatter)
+		logger.addHandler(file_handler2)
+
+		return logger
+
+	@staticmethod
+	def logger_file(log_file, log_name):
+		logger = logging.getLogger(log_name)
+		logger.setLevel(logging.DEBUG)
+		# format
+		formatter = logging.Formatter(fmt='%(asctime)s - %(filename)s[%(lineno)d] - %(levelname)s - %(message)s',
+									  datefmt='%Y/%m/%d %H:%M:%S')
+
+		# StreamHandler
+		stream_handler = logging.StreamHandler(sys.stdout)
+		stream_handler.setFormatter(formatter)
+		logger.addHandler(stream_handler)
+
+		# # FileHandler
+		file_handler = logging.FileHandler(log_file)
+		file_handler.setFormatter(formatter)
+		logger.addHandler(file_handler)
+
+		return logger

+ 73 - 0
dgp/tests/test.py

@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+@Time    : 2020/9/25 13:36
+@Author  : zhengwangeng
+@Software: PyCharm
+
+# code is far away from bugs with the god animal protecting
+    I love animals. They taste delicious.
+              ┏┓      ┏┓
+            ┏┛┻━━━┛┻┓
+            ┃      ☃      ┃
+            ┃  ┳┛  ┗┳  ┃
+            ┃      ┻      ┃
+            ┗━┓      ┏━┛
+                ┃      ┗━━━┓
+                ┃  神兽保佑    ┣┓
+                ┃ 永无BUG!   ┏┛
+                ┗┓┓┏━┳┓┏┛
+                  ┃┫┫  ┃┫┫
+                  ┗┻┛  ┗┻┛
+"""
+
+import time
+from apscheduler.schedulers.blocking import BlockingScheduler
+from logger import LoggerService
+# import account_list as al
+
+
+def start_order_job(log):
+	log.info('start_order_job')
+	# log.info(len(al.yuewen_account_list))
+	st_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
+	et_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600)
+	# print(st_unix, et_unix)
+	st_unix = 1600736400;
+	et_unix = 1600740000;
+	# print(st_unix, et_unix)
+	# et_unix = et_unix - 1
+	st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
+	et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
+	# log.info(st_dt + '\t' + et_dt)
+
+
+start_order_time = '2020-09-21 16:05:00'
+start_cost_time = '2020-09-21 16:35:00'
+
+if __name__ == '__main__':
+	log = LoggerService.logger_file('abc.log', 'abcd')
+	st_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
+	et_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600)
+	now_unix = int((time.time() + 8 * 3600) // 86400 * 86400 - 8 * 3600)
+
+	log.info(st_unix)
+	log.info(et_unix)
+	log.info(now_unix)
+
+	st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
+	et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
+	now_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(now_unix)) + '+08:00'
+
+	log.info(st_dt)
+	log.info(et_dt)
+	log.info(now_dt)
+
+	data = (int((time.time() + 8 * 3600) // 86400 * 86400 - 8 * 3600))
+	log.info(data)
+
+	scheduler = BlockingScheduler()
+	scheduler.add_job(start_order_job, args=(log,), trigger='interval', max_instances=10, seconds=10,
+					  start_date=start_order_time)
+	scheduler.start()