Class: WebAnalyticsDiscovery::LiveInternet

Inherits:
Object
  • Object
show all
Includes:
GrabberUtils
Defined in:
lib/web_analytics_discovery/grabber/liveinternet.rb

Constant Summary

Constants included from GrabberUtils

GrabberUtils::AVG_DAYS_IN_MONTH, GrabberUtils::CACHE_DIR, GrabberUtils::USER_AGENT

Instance Method Summary collapse

Methods included from GrabberUtils

#download, #download_file, #mangle_url

Instance Method Details

#find_idObject



16
17
18
19
20
21
22
23
24
# File 'lib/web_analytics_discovery/grabber/liveinternet.rb', line 16

def find_id
  case @page
  when /new Image\(\)\.src = "\/\/counter\.yadro\.ru\/hit;([^?"]+)\?/
    $1
  else
    # Use hostname as a last resort measure
    URI.parse(@url).host
  end
end

#run(url) ⇒ Object



10
11
12
13
14
# File 'lib/web_analytics_discovery/grabber/liveinternet.rb', line 10

def run(url)
  @url = url
  @page = download(url)
  run_id(find_id)
end

#run_id(host) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/web_analytics_discovery/grabber/liveinternet.rb', line 26

def run_id(host)
  r = {:id => host}

  doc = download("http://www.liveinternet.ru/stat/#{host}/index.csv")
  r[:pv_day], r[:visits_day], r[:visitors_day] = grab_psv(doc, 4)

  # Bail out early if no LiveInternet data available
  return r unless r[:pv_day]

  doc = download("http://www.liveinternet.ru/stat/#{host}/index.csv?period=week;total=yes")
  r[:pv_week], r[:visits_week], r[:visitors_week] = grab_psv(doc, 2)

  doc = download("http://www.liveinternet.ru/stat/#{host}/index.csv?period=month;total=yes")
  r[:pv_mon], r[:visits_mon], r[:visitors_mon] = grab_psv(doc, 2)

  return r
end