Last active
July 4, 2019 16:18
-
-
Save rohitvvv/511acbee2ae01590b017b111d3e105d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment