-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse_users.py
More file actions
51 lines (36 loc) · 1.59 KB
/
parse_users.py
File metadata and controls
51 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import datetime
def date_range_list(start_date, end_date):
# Return list of datetime.date objects between start_date and end_date (inclusive).
date_list = []
curr_date = start_date
while curr_date <= end_date:
date_list.append(curr_date.strftime('%Y%m%d'))
curr_date += datetime.timedelta(days=1)
return date_list
start_date = datetime.date(year=2022, month=11, day=1)
stop_date = datetime.date(year=2023, month=1, day=31)
date_list = date_range_list(start_date, stop_date)
file_path = 'q4'
user_sessions = {}
for date in date_list:
user_file = file_path + '/{}.txt'.format(date)
with open(user_file, 'r', encoding='utf-8') as user_file_open:
file_lines = user_file_open.readlines()
for line in file_lines:
if "Login.Success" in line:
split_line = " ".join(line.split()).split("|")[0].strip().split(" ")
username = " ".join(split_line[4:-1])
session_id = split_line[-1]
user_sessions[session_id] = username
user_tracker = []
for date in date_list:
user_file = file_path + '/spu{}.log'.format(date)
with open(user_file, 'r', encoding='utf-8') as user_file_open:
file_lines = user_file_open.readlines()
for line in file_lines:
if "wiley.com" in line:
session_id = " ".join(line.split()).split(" ")[2]
username = user_sessions[session_id]
if username not in user_tracker:
user_tracker.append(username)
print(len(user_tracker))