Class: Worldfootball::Metal

Inherits:
Metal::Base show all
Defined in:
lib/webget-football/worldfootball/download.rb

Overview

todo/check: put in Downloader namespace/class - why? why not?

or use Metal    - no "porcelain" downloaders / machinery

Constant Summary collapse

BASE_URL =
'https://www.weltfussball.de'

Class Method Summary collapse

Methods inherited from Metal::Base

download_page

Class Method Details

.download_report(slug, cache: true) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/webget-football/worldfootball/download.rb', line 81

def self.download_report( slug, cache: true )
  url  = report_url( slug )

  ## check check first
  if cache && Webcache.cached?( url )
     puts "  reuse local (cached) copy >#{Webcache.url_to_id( url )}<"
  else
    download_page( url )
  end
end

.download_reports_for_schedule(slug, cache: true) ⇒ Object

todo/check: rename to reports_for_schedule or such - why? why not?



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/webget-football/worldfootball/download.rb', line 93

def self.download_reports_for_schedule( slug, cache: true ) ## todo/check: rename to reports_for_schedule or such - why? why not?

  page = Page::Schedule.from_cache( slug )
  matches = page.matches

  puts "matches - #{matches.size} rows:"
  pp matches[0]

  puts "#{page.generated_in_days_ago}  - #{page.generated}"

  ## todo/fix: restore sleep to old value at the end!!!!
  ## Webget.config.sleep = 8    ## fetch 7-8 pages/min

  matches.each_with_index do |match,i|
     est = (Webget.config.sleep * (matches.size-(i+1)))/60.0   # estimated time left

     puts "fetching #{i+1}/#{matches.size} (#{est} min(s)) - #{match[:round]} | #{match[:team1]} v #{match[:team2]}..."
     report_ref = match[:report_ref ]
     if report_ref
       download_report( report_ref, cache: cache )
     else
       puts "!! WARN: report ref missing for match:"
       pp match
     end
  end
end

.download_schedule(slug) ⇒ Object



76
77
78
79
# File 'lib/webget-football/worldfootball/download.rb', line 76

def self.download_schedule( slug )
  url = schedule_url( slug )
  download_page( url )
end

.report_url(slug) ⇒ Object



50
# File 'lib/webget-football/worldfootball/download.rb', line 50

def self.report_url( slug )    "#{BASE_URL}/spielbericht/#{slug}/"; end

.schedule_url(slug) ⇒ Object



49
# File 'lib/webget-football/worldfootball/download.rb', line 49

def self.schedule_url( slug )  "#{BASE_URL}/alle_spiele/#{slug}/";  end