main.py 912 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import time
  2. import os
  3. def time_watcher():
  4. print('--- %s seconds ---' % (time.time() - start_time))
  5. def write_log(line, nameFile): # запись корректного лога
  6. path_f = os.path.dirname(os.path.abspath(__file__))
  7. with open(os.path.join(path_f, nameFile), "a") as log_file:
  8. log_file.write(line)
  9. def read_log():
  10. path_f = os.path.dirname(os.path.abspath(__file__))
  11. with open(os.path.join(path_f, "test.log")) as log_file:
  12. lines = [line.rstrip() for line in log_file]
  13. for i in range(len(lines)):
  14. try:
  15. string = lines[i].split('/" "')
  16. # print(string[1])
  17. write_log(string[1]+"\n", "user-agents.log")
  18. except:
  19. write_log(lines[i]+"\n", "wrong.log")
  20. def main():
  21. read_log()
  22. if __name__ == '__main__':
  23. start_time = time.time()
  24. main()
  25. time_watcher()