Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os;
- def extract_users(file):
- extract = {}
- csv_file = "users.csv"
- for line in file:
- if "/codenjoy-contest/ws?user=" in line:
- start = line.find("=")
- limit = line.find("\\u0026")
- startTime = line.find("\"time\":")
- endTime =line.find("\"}")
- if start < limit and start > 0 and limit > 0 and startTime > 0 and endTime > 0:
- user = line[start+1:limit]
- time = line[startTime+8:endTime]
- extract[user]=time
- try:
- with open(csv_file, 'a') as csvfile:
- for key, value in sorted( extract.items()):
- csvfile.write(str(key)+","+str(value)+"\n")
- except IOError:
- print("I/O error")
- def process_logs_at_path(path):
- for file in os.listdir(path):
- if file.endswith(".log"):
- file_to_process = open(path+file, "r")
- extract_users(file_to_process)
- process_logs_at_path("/Users/rohitvaidya/Documents/project/GetUserInfo/.idea/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement