店播爬取Python脚本

print_log.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import time
  2. import sys
  3. class PrintLog:
  4. @staticmethod
  5. def print(content):
  6. script_path = sys.path[0]
  7. logfile = script_path + '/log/data/' + PrintLog.script_name() + '_' + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  8. file = open(logfile, 'a', encoding='utf8')
  9. content = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + content
  10. file.write(content + '\n')
  11. # 关闭文件
  12. file.close()
  13. @staticmethod
  14. def script_name() :
  15. argv0_list = sys.argv[0].split('/')
  16. script_name = argv0_list[len(argv0_list) - 1] # get script file name self
  17. script_name = script_name[0:-3] # remove '.py'
  18. return script_name
  19. @staticmethod
  20. def write(content, file_name):
  21. script_path = sys.path[0]
  22. logfile = script_path + '/log/data/' + PrintLog.script_name() + '_' \
  23. + file_name + '_' + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  24. file = open(logfile, 'a', encoding='utf8')
  25. content = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + content
  26. file.write(content + '\n')
  27. # 关闭文件
  28. file.close()