uk.js
function extractTravelPlan(data) {
  let tickets = data.fullJourneys[0].cheapestTickets
  if (!tickets || tickets.length === 0) { return [] }
  let secondClass = tickets[0].tickets
  let firstClass = tickets[1].tickets
  let journeys = data.fullJourneys[0].journeys
  let date = data.fullJourneys[0].date  // "25 Sep 2016"

  let journeyFromId = []
  journeys.forEach(journey => journeyFromId[journey.id] = journey)

  let plans = []
  let getPlan = (from, to, departure, arrival) => {
    return plans.find(plan =>
      (plan.legs[0].from === from) && (plan.legs[0].to === to) &&
      (plan.legs[0].departure === departure) && (plan.legs[0].arrival === arrival))
  }

  let mkticket = (ticket, travelClass) => {
    let journey = journeyFromId[ticket.journeyId]
    let price = ticket.price  // "81.40"
    if (!journey || !price) { return }
    let origin = station.name(journey.departureName)
    let destination = station.name(journey.arrivalName)

    let from = origin ? origin.id : journey.departureName
    let to = destination ? destination.id : journey.arrivalName
    let departure = String(parseTime(date, journey.departureTime))
    let arrival = String(parseTime(date, journey.arrivalTime))
    let plan = getPlan(from, to, departure, arrival)
    if (plan === undefined) {
      plan = {
        fares: [],
        legs: [{from, to, departure, arrival}],
      }
      plans.push(plan)
    }

    plan.fares.push({
      class: travelClass,
      flexibility: 1,
      price: [{ cents: parsePrice(ticket.price), currency: 'GBP' }],
    })
  }
  secondClass.map(ticket => mkticket(ticket, 2))
  firstClass.map(ticket => mkticket(ticket, 1))
  return plans
}
function extractTravelPlan(data) {
  let tickets = data.fullJourneys[0].cheapestTickets
  if (!tickets || tickets.length === 0) { return [] }
  let secondClass = tickets[0].tickets
  let firstClass = tickets[1].tickets
  let journeys = data.fullJourneys[0].journeys
  let date = data.fullJourneys[0].date  // "25 Sep 2016"

  let journeyFromId = []
  journeys.forEach(journey => journeyFromId[journey.id] = journey)

  let plans = []
  let getPlan = (from, to, departure, arrival) => {
    return plans.find(plan =>
      (plan.legs[0].from === from) && (plan.legs[0].to === to) &&
      (plan.legs[0].departure === departure) && (plan.legs[0].arrival === arrival))
  }

  let mkticket = (ticket, travelClass) => {
    let journey = journeyFromId[ticket.journeyId]
    let price = ticket.price  // "81.40"
    if (!journey || !price) { return }
    let origin = station.name(journey.departureName)
    let destination = station.name(journey.arrivalName)

    let from = origin ? origin.id : journey.departureName
    let to = destination ? destination.id : journey.arrivalName
    let departure = String(parseTime(date, journey.departureTime))
    let arrival = String(parseTime(date, journey.arrivalTime))
    let plan = getPlan(from, to, departure, arrival)
    if (plan === undefined) {
      plan = {
        fares: [],
        legs: [{from, to, departure, arrival}],
      }
      plans.push(plan)
    }

    plan.fares.push({
      class: travelClass,
      flexibility: 1,
      price: [{ cents: parsePrice(ticket.price), currency: 'GBP' }],
    })
  }
  secondClass.map(ticket => mkticket(ticket, 2))
  firstClass.map(ticket => mkticket(ticket, 1))
  return plans
}
function extractTravelPlan ( data ) { let tickets = data . fullJourneys [ 0 ] . cheapestTickets if ( ! tickets || tickets . length === 0 ) { return [ ] } let secondClass = tickets [ 0 ] . tickets let firstClass = tickets [ 1 ] . tickets let journeys = data . fullJourneys [ 0 ] . journeys let date = data . fullJourneys [ 0 ] . date // "25 Sep 2016" let journeyFromId = [ ] journeys . forEach ( journey => journeyFromId [ journey . id ] = journey ) let plans = [ ] let getPlan = ( from , to , departure , arrival ) => { return plans . find ( plan => ( plan . legs [ 0 ] . from === from ) && ( plan . legs [ 0 ] . to === to ) && ( plan . legs [ 0 ] . departure === departure ) && ( plan . legs [ 0 ] . arrival === arrival ) ) } let mkticket = ( ticket , travelClass ) => { let journey = journeyFromId [ ticket . journeyId ] let price = ticket . price // "81.40" if ( ! journey || ! price ) { return } let origin = station . name ( journey . departureName ) let destination = station . name ( journey . arrivalName ) let from = origin ? origin . id : journey . departureName let to = destination ? destination . id : journey . arrivalName let departure = String ( parseTime ( date , journey . departureTime ) ) let arrival = String ( parseTime ( date , journey . arrivalTime ) ) let plan = getPlan ( from , to , departure , arrival ) if ( plan === undefined ) { plan = { fares : [ ] , legs : [ { from , to , departure , arrival } ] , } plans . push ( plan ) } plan . fares . push ( { class : travelClass , flexibility : 1 , price : [ { cents : parsePrice ( ticket . price ) , currency : 'GBP' } ] , } ) } secondClass . map ( ticket => mkticket ( ticket , 2 ) ) firstClass . map ( ticket => mkticket ( ticket , 1 ) ) return plans }
Get raw scrapping data Return data conforming to the common travel plan format.
Get raw scrapping data Return data conforming to the common travel plan format .