Add monthly visitors functionality #1

Merged
miguel456 merged 6 commits from feat/monthly-visitors into main 2024-05-20 13:31:19 +00:00
1 changed files with 12 additions and 4 deletions
Showing only changes of commit 87706021c3 - Show all commits

12
main.rb
View File

@ -42,8 +42,11 @@ end
# Returns the date in the current line
def get_line_date(line)
pattern = /\[(.*?)\]/
match = line.match(pattern)[0] if line.match(pattern)
if line.match(pattern)
match = line.match(pattern)[0]
else
raise StandardError("Invalid datetime data detected!")
end
# [12/Apr/2023:13:56:41 +0100] -> 12/Apr/2023:13:56:41 +0100 -> Apr/2023
Date.parse(match.gsub('[', '').gsub(']', '')).strftime('%b/%Y')
end
@ -110,7 +113,12 @@ lines.each do |line|
ip = get_line_ip(line).to_s
code = get_line_code(line)
ua = get_line_ua(line)
begin
date = get_line_date(line)
rescue StandardError
date = 'N/A'
end
if is_client_err?(code.to_i)
if client_errors[ip]