| Class | Wikipedia |
| In: |
app/models/wikipedia.rb
|
| Parent: | Object |
| WikipediaFolder | = | 'wikipedia/' |
# File app/models/wikipedia.rb, line 4 4: def is_today(t) 5: n=Time.now 6: # logger.info "filet #{t} nowis #{n}" 7: (n.year==t.year) and (n.yday==t.yday) 8: end
# File app/models/wikipedia.rb, line 10
10: def page(search_word)
11: wd=WikipediaFolder.chop
12: Dir.mkdir(wd) unless File.directory?(wd)
13: wfile=WikipediaFolder+
14: search_word.downcase+'.html'
15: if !File.exist?(wfile) ||
16: !is_today(File.mtime(wfile))
17: search_word[0]=search_word[0,1].upcase
18: #wikipedia likes the first char large
19: begin
20: pg=Net::HTTP.
21: get('en.wikipedia.org','/wiki/'+ search_word)
22: open(wfile,'w') {|f| f.puts pg }
23: # logger.info "#{search_word} page downloaded"
24: rescue Exception
25: # p("unable to download: #{$!}")
26: if File.exist?(wfile)
27: open(wfile,'r') {|f| pg=f.read }
28: # logger.info "no access, using stored
29: #{search_word}"
30: else
31: pg=''
32: # logger.info("stored page for #{
33: # search_word} not available")
34: end
35: end
36: else
37: open(wfile,'r') {|f| pg=f.read }
38: # logger.info "wikicache for #{search_word} is
39: # current"
40: end
41: pg
42: end