<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,6 @@
 # Methods added to this helper will be available to all templates in the application.
 module ApplicationHelper
+  def wikipedia_link(str)
+    link_to str,&quot;http://en.wikipedia.org/wiki/Special:Search/&quot; + str + &quot;_&quot; + &quot;airport&quot;
+  end
 end</diff>
      <filename>app/helpers/application_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 &lt;img src='ejectlarge.jpg' style='float:right'&gt;
 &lt;h1&gt;EJECT.ME&lt;/h1&gt;
 &lt;h2&gt;Emergency air travel&lt;/h2&gt;
-You're going to &lt;%= @flights[:outgoing].to_airport %&gt; on &lt;%= @flights[:outgoing].departs_at.strftime(&quot;%a %d %B&quot;) %&gt; and returning on &lt;%= @flights[:incoming].departs_at.strftime(&quot;%a %d %B&quot;) %&gt;. All-in price per person (excluding airport transfers) is &lt;%= number_to_currency(@flights[:outgoing].price + @flights[:incoming].price,:unit=&gt;&quot;&#163;&quot;) %&gt;.
+You're going to &lt;%= wikipedia_link(@flights[:outgoing].to_airport) %&gt; on &lt;%= @flights[:outgoing].departs_at.strftime(&quot;%a %d %B&quot;) %&gt; and returning on &lt;%= @flights[:incoming].departs_at.strftime(&quot;%a %d %B&quot;) %&gt;. All-in price per person (excluding airport transfers) is &lt;%= number_to_currency(@flights[:outgoing].price + @flights[:incoming].price,:unit=&gt;&quot;&#163;&quot;) %&gt;.
 </diff>
      <filename>app/views/home/index.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -1,43 +1,35 @@
 class RyanairScraper &lt; Scraper
   
-  def self.rebuild_flights
+  def self.build_all_flights
     from_airport = &quot;STN&quot;
-    to_airports = %w(ORK NRN PIK NOC LRH MRS PMF PEG PIS NYO)
+    to_airports = %w(RYG ORK NRN NOC LRH MRS PMF PEG PIS NYO)
 
     to_airports.each do |to_airport|
-      upcoming_outgoing_dates.each do |date|
-        price = self.price_for_flight(date,from_airport,to_airport)
-        puts &quot;#{from_airport} -&gt; #{to_airport} on #{date.to_s}: GBP #{price}&quot;
-        Flight.create!(:from_airport=&gt;from_airport,:to_airport=&gt;to_airport,:departs_at=&gt;date,:price=&gt;price) if price
-      end
-      upcoming_incoming_dates.each do |date|
-        price = self.price_for_flight(date,to_airport,from_airport)
-        puts &quot;#{to_airport} -&gt; #{from_airport} on #{date.to_s}: GBP #{price}&quot;
-        Flight.create!(:from_airport=&gt;to_airport,:to_airport=&gt;from_airport,:departs_at=&gt;date,:price=&gt;price) if price
+      upcoming_dates.each do |date|
+        self.build_flights(date,from_airport,to_airport)
+        puts &quot;#{from_airport} -&gt; #{to_airport} on #{date.to_s}&quot;
       end
     end
   end
   
-  def self.upcoming_outgoing_dates
-    (1..30).collect{|n| n.days.from_now}.select{|d| %w(Fri Sat).include?(d.strftime(&quot;%a&quot;))}.compact
-  end
-  def self.upcoming_incoming_dates
-    (3..32).collect{|n| n.days.from_now}.select{|d| %w(Sun Mon).include?(d.strftime(&quot;%a&quot;))}.compact
+  def self.upcoming_dates
+    (1..30).collect{|n| n.days.from_now}.select{|d| %w(Fri Sat Sun Mon).include?(d.strftime(&quot;%a&quot;))}.compact
   end
     
   #Query ryanair and create a Flight object 
-  def self.price_for_flight(date,from_string,to_string)
-    prices = []
+  def self.build_flights(date,from_string,to_string)
     agent = WWW::Mechanize.new
-   # agent.set_proxy(&quot;127.0.0.1&quot;, 8888)
+    #agent.set_proxy(&quot;127.0.0.1&quot;, 8888)
     page = agent.get('http://ryanair.com/php/sbforms/form.php?val=GB')
     booking_form = page.forms.first
     booking_form.sector1_o = &quot;a&quot; + from_string
     booking_form.sector1_d = to_string
     booking_form.delete_field!(&quot;SearchBy&quot;)
     booking_form.date1 = date.strftime(&quot;%Y%m%d&quot;)
+    booking_form.date2 = date.strftime(&quot;%Y%m%d&quot;)
     booking_form.m1 = date.strftime(&quot;%Y%m%d&quot;) + &quot;a&quot; + from_string + to_string
-    booking_form.nom = &quot;1&quot;
+    booking_form.m1 = date.strftime(&quot;%Y%m%d&quot;) + to_string + &quot;a&quot; + from_string
+    booking_form.nom = &quot;2&quot;
     booking_form.pM = &quot;0&quot;
     booking_form.tc = &quot;1&quot;
     booking_form.pT = &quot;1ADULT&quot;
@@ -49,31 +41,41 @@ class RyanairScraper &lt; Scraper
     results_page = agent.submit(booking_form)
     
     return nil unless results_page.root.to_s.index(&quot;Regular&quot;) #no flights on this date
-    
+        
     #now break out the flight keys
-    keys = self.get_flight_keys(results_page)
+    outgoing_keys = self.get_keys(results_page,&quot;AvailabilityInputFRSelectView$market1&quot;)
+    incoming_keys = self.get_keys(results_page,&quot;AvailabilityInputFRSelectView$market2&quot;)
+
+    #get the prices
+    best_outgoing_price = self.best_price(agent,outgoing_keys)
+    best_incoming_price = self.best_price(agent,incoming_keys)
+        
+    #later, get date from the key
+    Flight.create!(:from_airport=&gt;from_string,:to_airport=&gt;to_string,:departs_at=&gt;date,:price=&gt;best_outgoing_price) if best_outgoing_price
+    Flight.create!(:from_airport=&gt;to_string,:to_airport=&gt;from_string,:departs_at=&gt;date,:price=&gt;best_incoming_price) if best_incoming_price
+  end
+  
+private
 
-    #make a request for each one
+  def self.best_price(agent,keys)
+    prices = []
     keys.each do |key|
       detail = agent.get(&quot;http://www.bookryanair.com/skysales/FRTaxAndFeeInclusiveDisplay-resource.aspx?flightKeys=#{key}&amp;numberOfMarkets=1&amp;keyDelimeter=+++&quot;)
       prices &lt;&lt; self.get_price_from_detail_page(detail)
     end
-    
-    prices.compact.sort.first
+    prices.compact.sort.uniq.first
   end
-  
-private
 
-  def self.get_flight_keys(results_page)
+  def self.get_keys(results_page,v)
     keys = []
     results_page.search(&quot;//input&quot;).each do |inp|
-      if inp.attributes[&quot;name&quot;].to_s.strip == &quot;AvailabilityInputFRSelectView$market2&quot;
+      if inp.attributes[&quot;name&quot;].to_s.strip == v
         keys &lt;&lt; inp.attributes[&quot;value&quot;].to_s.strip
       end
     end
     keys
   end
-  
+    
   def self.get_price_from_detail_page(detail_page)
     detail_page.search(&quot;//td&quot;)[-2].children.to_s.to_f 
   end</diff>
      <filename>lib/ryanair_scraper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f8a081b3e6395d2b4bf1ca49078a05902d630298</id>
    </parent>
  </parents>
  <author>
    <name>Gwyn Morfey</name>
    <email>gwyn@Unknown-00-23-6c-89-83-be.config</email>
  </author>
  <url>http://github.com/gwynm/ejectme/commit/bc51752ac3b2d094e3e272f1c023465e035c294e</url>
  <id>bc51752ac3b2d094e3e272f1c023465e035c294e</id>
  <committed-date>2009-11-06T08:47:54-08:00</committed-date>
  <authored-date>2009-11-06T08:47:54-08:00</authored-date>
  <message>Fixed return flight bug?</message>
  <tree>a12dd8482faabe6e5d65308d398f0343a0710ead</tree>
  <committer>
    <name>Gwyn Morfey</name>
    <email>gwyn@Unknown-00-23-6c-89-83-be.config</email>
  </committer>
</commit>
