<commit_before>require 'mechanize'

class Flyday
  attr_reader :airline

  def initialize
    @airline = 'southwest'
    @mechanize = Mechanize.new
    @mechanize.agent.user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
    # @mechanize.agent.set_proxy 'localhost', 8888
    # @mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    # @mechanize.agent.certificate='charles.crt'
    @mechanize.log = Logger.new "flyday.log"
  end

  def search_hash
    {
      "flowName" => "book",
      "omni_reload" => "false",
      "twoWayTrip" => "false",
      "returnAirport" => " ",
      "returnAirport_displayed" => " ",
      "fareType" => "DOLLARS",
      "originAirport" => "CAK",
      "originAirport_displayed" => "Akron-Canton, OH - CAK",
      "destinationAirport" => "ATL",
      "destinationAirport_displayed" => "Atlanta, GA - ATL",
      "outboundDateString" => "01/15/2016",
      "omni_outboundDateString" => "01/15/2016",
      "returnDateString" => " ",
      "omni_returnDateString" => "01/16/2016",
      "outboundTimeOfDay" => "ANYTIME",
      "returnTimeOfDay" => " ",
      "adultPassengerCount" => "1",
      "seniorPassengerCount" => "0",
      "promoCode" => " ",
      "serviceID" => "flightoptions",
      "appID" => "swa",
      "appver" => "2.19.0",
      "channel" => "wap",
      "platform" => "thinclient",
      "cacheid" => " ",
      "rcid" => "spaiphone",
    }
  end

  def search(date)
    # @mechanize.get('https://southwest.com/')
    # post = @mechanize.post('https://southwest.com/flight/search-flight.html',{
    #   'originAirport' => 'MDW',
    #   'twoWayTrip' => 'false',
    #   'promoCode ' => '',
    #   'returnDateString'  => '',
    #   'destinationAirport' => 'XYZ',
    #   'outboundDateString' => '01/14/2016',
    #   'adultPassengerCount' => '1',
    #   'seniorPassengerCount' => '0',
    #   'fareType' => 'DOLLARS',
    # })
    @mechanize.get('https://mobile.southwest.com')
    post = @mechanize.post('https://mobile.southwest.com/middleware/MWServlet',{
      serviceID: 'getTravelInfo',
      appID: 'swa',
      appver: '2.19.0',
      channel: 'wap',
      platform: 'thinclient',
      cacheid:' ',
      rcid: 'spaiphone'
    }, {"Content-Type" => "application/x-www-form-urlencoded"})
    # binding.pry
    File.write("hello.html", post.body)
    post = @mechanize.post('https://mobile.southwest.com/middleware/MWServlet',
    # 'flowName=book&omni_reload=false&twoWayTrip=false&returnAirport=&returnAirport_displayed=&fareType=DOLLARS&originAirport=CAK&originAirport_displayed=Akron-Canton%2C%20OH%20-%20CAK&destinationAirport=ATL&destinationAirport_displayed=Atlanta%2C%20GA%20-%20ATL&outboundDateString=01%2F15%2F2016&omni_outboundDateString=01%2F15%2F2016&returnDateString=&omni_returnDateString=01%2F16%2F2016&outboundTimeOfDay=ANYTIME&returnTimeOfDay=&adultPassengerCount=1&seniorPassengerCount=0&promoCode=&serviceID=flightoptions&appID=swa&appver=2.19.0&channel=wap&platform=thinclient&cacheid=&rcid=spaiphone',
    search_hash,
    {"Content-Type" => "application/x-www-form-urlencoded"})
    # File.write("hello.html", post.body)
    []<commit_msg>hard code the cookie, clean up time<commit_after>require 'mechanize'

class Flyday
  attr_reader :airline

  def initialize
    @airline = 'southwest'
    @mechanize = Mechanize.new
    @mechanize.agent.user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
    # @mechanize.agent.set_proxy 'localhost', 8888
    # @mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    # @mechanize.agent.certificate='charles.crt'
    @mechanize.log = Logger.new "flyday.log"
  end

  def search(date)
    post = @mechanize.post('https://mobile.southwest.com/middleware/MWServlet',
    'flowName=book&omni_reload=false&twoWayTrip=false&returnAirport=&returnAirport_displayed=&fareType=DOLLARS&originAirport=MDW&originAirport_displayed=Chicago%20(Midway)%2C%20IL%20-%20MDW&destinationAirport=ATL&destinationAirport_displayed=Atlanta%2C%20GA%20-%20ATL&outboundDateString=01%2F19%2F2016&omni_outboundDateString=01%2F19%2F2016&returnDateString=&omni_returnDateString=01%2F20%2F2016&outboundTimeOfDay=ANYTIME&returnTimeOfDay=&adultPassengerCount=1&seniorPassengerCount=0&promoCode=&serviceID=flightoptions&appID=swa&appver=2.19.0&channel=wap&platform=thinclient&cacheid=&rcid=spaiphone&',
    { 'Cookie' => 'cacheid=166fd301a3d-9f6b-40c0-9aa7-0b25dc9bb862;' })
    post.body
{'fraction_non_alphanumeric': 0.16143790849673204, 'fraction_numerical': 0.04814814814814815, 'mean_word_length': 4.4589774078478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3043836', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1721, 'n_words': 197}