-
-
Save cored/dcdeaa088beb42ea79b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "aldi/version" | |
require 'mechanize' | |
require 'open-uri' | |
module Aldi | |
end | |
module DeAldiFernbus | |
URL = "https://system04.derticketservice.de/".freeze | |
def self.find(from, to, date) | |
agent = Mechanize.new | |
agent.get(URL) | |
submited_form = build_form(agent, build_attributes(from, to, date)) | |
require 'pry'; binding.pry | |
# url = URI.encode build_url(build_attributes(from,to,date)) | |
# uri = URI.parse(url) | |
# conn = Faraday.new("#{uri.scheme}://#{uri.host}", {ssl: {verify: false} }) | |
# raw_html = conn.post "/search#{uri.request_uri}" | |
# require 'pry'; binding.pry | |
# html = raw_html.body | |
end | |
def self.build_attributes(from, to, date) | |
current_time = Time.now | |
attributes = { | |
departure:37, | |
destination:39, | |
ddate:date.strftime('%d.%m.%Y'), | |
dtime:"#{current_time.hour}:#{current_time.min}", | |
rdate:date.strftime('%d.%m.%Y'), | |
} | |
end | |
def self.build_form(agent, attributes) | |
agent.page.forms[0]["departure"] = attributes[:departure] | |
agent.page.forms[0]["destination"] = attributes[:destination] | |
agent.page.forms[0]["ddate"] = attributes[:ddate] | |
agent.page.forms[0]["dtime"] = attributes[:dtime] | |
agent.page.forms[0]["rdate"] = attributes[:rdate] | |
agent.page.forms[0]["roundtrip"] = 0 | |
agent.page.forms[0]["mode"] = "d" | |
agent | |
end | |
def self.build_url(attributes) | |
from = attributes[:departure] | |
destination = attributes[:destination] | |
departure_at = attributes[:ddate] | |
departure_time = attributes[:dtime] | |
return_date = attributes[:rdate] | |
url = URL.dup | |
url << "?departure=#{from}" | |
url << "&destination=#{destination}" | |
url << "&ddate=#{departure_at}" | |
url << "&dtime=#{departure_time}" | |
url << "&rdate=#{return_date}" | |
url << "&rtime=#{departure_time}" | |
url << "&roundtrip=0" | |
url << "&hash=#{retrieve_hash}" | |
url << "&mode=d" | |
url << "&search_do=Verbindung+finden" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment