Skip to content

Commit 86135ca

Browse files
author
root
committed
Update to access log analyser.
1 parent 7f3252f commit 86135ca

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tools/access_log_analyser.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,24 @@ def analyser(access_file_path):
129129
timestamp1 = ""
130130
for line in reverse_readline(access_file_path):
131131
if line:
132-
ip_addr, timestamp2, http = re.match(regex1, line).groups()
133-
if not timestamp1:
134-
timestamp1 = timestamp2
135-
if date_compare(timestamp1, timestamp2, hours=1):
136-
searches = '{"' + timestamp1 + '": ' + str(search_count) + '}'
137-
search_counts.append(searches)
138-
search_count = 0
139-
timestamp1 = timestamp2
140-
if "/search/?q=" in http:
141-
search_count = search_count + 1
142-
#query = regex2.search(http)
143-
#if query:
144-
#query = search_term_unescape(query.group(1))
145-
#if not "%" in query:
146-
#print query
132+
try:
133+
ip_addr, timestamp2, http = re.match(regex1, line).groups()
134+
if not timestamp1:
135+
timestamp1 = timestamp2
136+
if date_compare(timestamp1, timestamp2, hours=1):
137+
searches = '{"' + timestamp1 + '": ' + str(search_count) + '}'
138+
search_counts.append(searches)
139+
search_count = 0
140+
timestamp1 = timestamp2
141+
if "/search/?q=" in http:
142+
search_count = search_count + 1
143+
#query = regex2.search(http)
144+
#if query:
145+
#query = search_term_unescape(query.group(1))
146+
#if not "%" in query:
147+
#print query
148+
except Exception as e:
149+
print e
147150
json_data = '{"searches": [' + ",".join(search_counts) + ']}'
148151
json_pretty = valid_pretty_json(json_data)
149152
if json_pretty:

0 commit comments

Comments
 (0)