diff --git a/Rakefile b/Rakefile index dc290aff..6a9be477 100644 --- a/Rakefile +++ b/Rakefile @@ -13,3 +13,24 @@ Rake::TestTask.new do |t| end task :default => :test + +desc "parse logs" +task :parse_logs => [:environment] do + hits = {} + logfile = File.open '/var/log/nginx/neocities-sites.log.1', 'r' + while hit = logfile.gets + hit = hit.split ' ' + + # It says hits, but really we're tracking visits to index" + if hit[3] == '/' + hits[hit[1]] ||= 0 + hits[hit[1]] += 1 + end + end + logfile.close + + hits.each do |username,hitcount| + DB['update sites set hits=hits+? where username=?', hitcount, username].first + end + +end diff --git a/views/browse.slim b/views/browse.slim index ea984e61..45bfa566 100644 --- a/views/browse.slim +++ b/views/browse.slim @@ -13,7 +13,7 @@ .span3 h3 style="margin-left: 20px": a href="http://#{site.username}.neocities.org" target="_blank" #{site.username} .span3.text-right - p style="margin-right: 20px; margin-top: 10px" #{site.hits} hits
last updated #{site.updated_at.ago} + p style="margin-right: 20px; margin-top: 10px" #{site.hits} visits
last updated #{site.updated_at.ago} a href="http://#{site.username}.neocities.org" target="_blank": img src="/site_screenshots/#{ENV['RACK_ENV'] == 'development' ? 'victoria' : site.username}.jpg" - if @page_count > 1