feat(date): add explanatory comment, line separators for output

Signed-off-by: Miguel Nogueira <me@nogueira.codes>
This commit is contained in:
Miguel Nogueira 2024-05-20 10:15:36 +01:00
parent 87706021c3
commit f9db304c8f
Signed by: miguel456
GPG Key ID: 43EF15DB0CC86DDD
1 changed files with 3 additions and 1 deletions

View File

@ -46,6 +46,7 @@ def get_line_date(line)
match = line.match(pattern)[0] match = line.match(pattern)[0]
else else
raise StandardError("Invalid datetime data detected!") raise StandardError("Invalid datetime data detected!")
# Tests would help find the bug...
end end
# [12/Apr/2023:13:56:41 +0100] -> 12/Apr/2023:13:56:41 +0100 -> Apr/2023 # [12/Apr/2023:13:56:41 +0100] -> 12/Apr/2023:13:56:41 +0100 -> Apr/2023
Date.parse(match.gsub('[', '').gsub(']', '')).strftime('%b/%Y') Date.parse(match.gsub('[', '').gsub(']', '')).strftime('%b/%Y')
@ -159,7 +160,8 @@ top_client_errors.each do |ip, count|
end end
monthly_visits.each do |ip, visits| monthly_visits.each do |ip, visits|
puts "IP #{ip} had the following visits:" puts "------------ BY DATE ---------------"
puts("IP #{ip} had the following visits:")
visits.each do |date, count| visits.each do |date, count|
puts "#{date}: #{count} visits" puts "#{date}: #{count} visits"
end end