Class: RetrieveContent

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
script/retrieve_content.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) request



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'script/retrieve_content.rb', line 106

def request
  load_rails(options[:environment])
  source_options = {}
  source_options[:refresh_since] = get_refresh_since(options)
  if(options[:demofeed])
    source_options[:demofeed] = true
  end
  sources = get_page_sources(options)
  sources.each do |page_source|
    puts "\n'#{page_source.name}'"
    puts "Source url: #{page_source.feed_url(source_options)}"
    atom_entries = page_source.atom_entries(source_options)
    puts "Atom Entry count: #{atom_entries.size}"
  end
end

- (Object) sourceinfo



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'script/retrieve_content.rb', line 74

def sourceinfo
  load_rails(options[:environment])
  source_options = {}
  source_options[:refresh_since] = get_refresh_since(options)
  if(options[:demofeed])
    source_options[:demofeed] = true
  end
  sources = get_page_sources(options)
  sources.each do |page_source|
    puts "\n'#{page_source.name}'"
    if(!page_source.latest_source_time.blank?)
      puts "Latest source time at last update: #{page_source.latest_source_time.strftime("%B %e, %Y, %l:%M %p %Z")}"
    end
    puts "Source url: #{page_source.feed_url(source_options)}"
    puts "Active: #{(page_source.active? ? 'true' : 'false')}"
    if(options[:last])
      if(page_source.last_requested_at)
        puts "Last updated: #{page_source.last_requested_at.strftime("%B %e, %Y, %l:%M %p %Z")}"
        puts "Last request result: #{page_source.last_requested_success? ? 'success' : 'failure'}"
        puts "Last request information: #{page_source.last_requested_information.inspect}"        
      else
        puts "No last request information"
      end
    end
  end
end

- (Object) sources



61
62
63
64
65
66
# File 'script/retrieve_content.rb', line 61

def sources
  load_rails(options[:environment])
  source_options = {}
  source_options[:refresh_since] = get_refresh_since(options)
  puts PageSource.all(:order => 'name').map{|source| "#{source.name} (#{source.active? ? 'active' : 'inactive'})"}.join("\n")
end

- (Object) update



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'script/retrieve_content.rb', line 127

def update
  load_rails(options[:environment])
  errors = []
  lockfile = Lockfile.new('/tmp/retrieve_content.lock', :retries => 0)
  begin
    lockfile.lock do    
      source_options = {}
      source_options[:refresh_since] = get_refresh_since(options)
      if(options[:demofeed])
        source_options[:demofeed] = true
      end
      sources = get_page_sources(options)
      sources.each do |page_source|
        puts "\n'#{page_source.name}'"
        puts "Source url: #{page_source.feed_url(source_options)}"
        result = page_source.retrieve_content(source_options)
        puts "Results:"
        puts "#{result.inspect}"
        if(!page_source.last_requested_success?)
          errors << page_source.name
        end
      end
    end
  rescue Lockfile::MaxTriesLockError => e
    $stderr.puts "Another content fetcher is already running. Exiting."
  end
  
  if(!errors.blank?)
    $stderr.puts "There were errors with the following page sources:  #{errors.join(',')}"
    $stderr.puts "Please run retrieve_content sourceinfo --last to get more information"
  end
end