Class: WebAnalyticsDiscovery::Openstat

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

Constant Summary collapse

BIG_SITE_ID =
601119

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



14
15
16
17
18
19
20
21
22
23
# File 'lib/web_analytics_discovery/grabber/openstat.rb', line 14

def find_id
  case @page
  when /<span id="(?:openstat|spylog)(\d+)"><\/span>/
    $1
  when /<img src=["']?http:\/\/u([0-9.]+)\.spylog\.com\/cnt/
    $1.gsub(/[.]/, '').to_i
  else
    nil
  end
end

#grab(doc, classname) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/web_analytics_discovery/grabber/openstat.rb', line 34

def grab(doc, classname)
  a = []
  doc.gsub(/#{classname}">([^<]+)<\/td>/) {
    r = $1
    r.gsub!(/&nbsp;/, '')
    a << r.to_i
  }
  return a
end

#run(url) ⇒ Object



9
10
11
12
# File 'lib/web_analytics_discovery/grabber/openstat.rb', line 9

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

#run_id(id) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/web_analytics_discovery/grabber/openstat.rb', line 25

def run_id(id)
  return nil unless id
  r = {:id => id}
  doc = download("http://rating.openstat.ru/site/#{id}")
  r[:visitors_day], r[:visits_day], r[:pv_day] = grab(doc, 'osb-rating_site-e-table-col-m-day')
  r[:visitors_mon], r[:visits_mon], r[:pv_mon] = grab(doc, 'osb-rating_site-e-table-col-m-month')
  return r
end