Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import os;
  2.  
  3. def extract_users(file):
  4. extract = {}
  5. csv_file = "users.csv"
  6. for line in file:
  7. if "/codenjoy-contest/ws?user=" in line:
  8. start = line.find("=")
  9. limit = line.find("\\u0026")
  10. startTime = line.find("\"time\":")
  11. endTime =line.find("\"}")
  12. if start < limit and start > 0 and limit > 0 and startTime > 0 and endTime > 0:
  13. user = line[start+1:limit]
  14. time = line[startTime+8:endTime]
  15. extract[user]=time
  16. try:
  17. with open(csv_file, 'a') as csvfile:
  18. for key, value in sorted( extract.items()):
  19. csvfile.write(str(key)+","+str(value)+"\n")
  20. except IOError:
  21. print("I/O error")
  22.  
  23. def process_logs_at_path(path):
  24. for file in os.listdir(path):
  25. if file.endswith(".log"):
  26. file_to_process = open(path+file, "r")
  27. extract_users(file_to_process)
  28.  
  29.  
  30. process_logs_at_path("/Users/rohitvaidya/Documents/project/GetUserInfo/.idea/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement