-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskyscraper.rb
More file actions
executable file
·64 lines (50 loc) · 1.4 KB
/
skyscraper.rb
File metadata and controls
executable file
·64 lines (50 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/ruby
# encoding: utf-8
# Scrape the flight search web site Kayak for specific flights, save them to a sqlite db and mail the results to a specific mail adress
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require 'erb'
require_relative 'origin'
$SUMMARY_TEMPLATE_FILE ='summary.html.erb'
class Skyscraper
def initialize(origins)
@origins = Hash.new
origins.each do |o|
@origins[o] = Origin.new o
end
end
def html_summary
ERB.new(File.read($SUMMARY_TEMPLATE_FILE), nil, '>').result(binding)
end
def text_summary
sum = String.new
@origins.values.each do |o|
sum << "Ergebnisse für #{o.origin}\n"
sum << "URL: #{o.url}\n"
sum << o.last_results.join("\n") << "\n\n"
end
sum
end
def mail_summary(email)
sum = html_summary
sum_text = text_summary
mail = Mail.deliver do
delivery_method :sendmail
to "#{email}"
from 'Fluguebersicht <123morph@gmail.com>'
subject "Flugsuche vom #{Time.now.strftime('%d.%m.%Y um %H:%M Uhr')}"
text_part do
content_type 'text/plain; charset=UTF-8'
body sum_text
end
html_part do
content_type 'text/html; charset=UTF-8'
body sum
end
end
end
end
s = Skyscraper.new [:DUS, :CGN, :FRA]
s.mail_summary 'franz.kirchhoff@googlemail.com'
# s.mail_summary 'u.b.lelgemann@googlemail.com'