def loadtraindata(): """ To load train stations on startup :return: Map of train stations with code as key and train station as value """ trainstationsmap = {} q = "MATCH (n:TRAINSTATION) return n" try: trainstations = DATABASE_CONNECTION.query(q) except Exception as e: logger = loggerUtil.getlogger("loaddata") print "Error" logger.error("Error in loading train data on startup, reason [%s]", e.message) return trainstationsmap if len(trainstations.elements) == 0: print "empty" return trainstationsmap for i in range(len(trainstations.elements)): trainstation = TrainStation() trainstation.code = trainstations.elements[i][0]['data']['CODE'] trainstation.name = trainstations.elements[i][0]['data']['NAME'] trainstation.city = trainstations.elements[i][0]['data']['CITY'] trainstationsmap[trainstation.code] = trainstation print "success" return trainstationsmap
# -*- coding: utf-8 -*- import time import logging import requests import loggerUtil try: import lxml.etree as etree except ImportError: import xml.etree.ElementTree as etree log = loggerUtil.getlogger("SkyScannerLib") STRICT, GRACEFUL, IGNORE = 'strict', 'graceful', 'ignore' class ExceededRetries(Exception): """Is thrown when allowed number of polls were performed but response is not complete yet.""" pass class EmptyResponse(Exception): """Is thrown when API returns empty response.""" pass class MissingParameter(KeyError): """Is thrown when expected request parameter is missing.""" pass class Transport(object):
# __author__ = 'ankur' import requests from requests.auth import HTTPDigestAuth import dateTimeUtility import loggerUtil, models import TravelPlanner.startuputil import CreateXml logger = loggerUtil.getlogger("BusApi") class BusController: """Class returns all stations corresponding to a city""" def getresults(self, source, destination, journeydate, numberofadults=1): response = {"bus": []} try: source = TravelPlanner.startuputil.getbuscity(source) destination = TravelPlanner.startuputil.getbuscity(destination) logger.debug("[START]-Get Results From BusApi for Source:[%s] and Destination:[%s],JourneyDate:[%s] ",source,destination,journeydate) travrlYaariResponse = CreateXml.getroutes(journeydate,source,destination) jdlist = journeydate.split("-") newformatjourneydate = jdlist[2]+"-"+jdlist[1]+"-"+jdlist[0] url = "http://agent.etravelsmart.com/etsAPI/api/getAvailableBuses?sourceCity="+source+"&destinationCity="+destination+"&doj="+newformatjourneydate req = requests.get(url, auth=HTTPDigestAuth('eazzer', 'E@ZZer1713'), timeout=20) jsonData = req.json() jsonData["apiAvailableBuses"].extend(travrlYaariResponse["apiAvailableBuses"]) response = self.parseresultandreturnfare(jsonData,source,destination,journeydate,newformatjourneydate,numberofadults)
__author__ = 'Hello' import loggerUtil, flightutil, flightSkyScanner, miscUtility, TravelPlanner.startuputil import concurrent logger = loggerUtil.getlogger("FlightDirectApi") class FlightDirectController: """ To get only direct flighte between source and destination cities """ def getresults(self, sourcecity, destinationcity, journeydate, flightclass, numberofadults): logger.debug( "[START]-Get Results From FlightDirectApi for Source:[%s] to Destination:[%s] on JourneyDate:[%s] ", sourcecity, destinationcity, journeydate) with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: source = TravelPlanner.startuputil.gettraincity(sourcecity).title() destination = TravelPlanner.startuputil.gettraincity( destinationcity).title() airports = flightutil.getnearestairports(source, destination) sourcenear = airports.sourceairports.near destinationnear = airports.destinationairports.near if source != sourcenear and destination != destinationnear: logger.warning(
__author__ = 'Hello' import loggerUtil, flightutil, flightSkyScanner, miscUtility, TravelPlanner.startuputil import concurrent, copy logger = loggerUtil.getlogger("FlightNearBigApi") class FlightNearBigAirportController: """ To get flights between source and destination cities, via big airports """ def getresults(self, sourcecity, destinationcity, journeydate, trainclass='3A', flightclass='economy', numberofadults=1): logger.debug( "[START]-Get Results From FlightNearBigApi for Source:[%s] to Destination:[%s] on JourneyDate:[%s] ", sourcecity, destinationcity, journeydate) with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: source = TravelPlanner.startuputil.gettraincity(sourcecity).title() destination = TravelPlanner.startuputil.gettraincity( destinationcity).title() airports = flightutil.getnearestairports(source, destination)
import sets import json, time, datetime, urllib2 import distanceutil, busapi, loggerUtil, googleapiparser, models, TravelPlanner.startuputil, trainapiutil, breakingcityutil __author__ = 'ankur' today = datetime.date.today().strftime("%Y-%m-%d") skipvalues = sets.Set( ['RAILWAY', 'STATION', 'JUNCTION', 'CITY', 'CANTT', 'JN']) logger = loggerUtil.getlogger("TrainApiNeo4j") class TrainController: """Entry point to get all routes with train as the major mode of transport""" def gettrainroutes(self, sourcecity, destinationstationset, journeydate, trainid, destinationcity, priceclass='3A', numberofadults=1, nextday=False, directtrainset=sets.Set()): """ to get list of all possible routes along with fare between all stations of source city and destination stations :param sourcecity: source of the journey :param destinationstationset: set of destination city's stations :param journeydate: journey date in 'dd-mm-yyyy' format :param trainid: train route id :param directtrainset: set of direct train numbers from source to destination, used for filtering out all direct trains in breaking journey
__author__ = 'Hello' import loggerUtil, flightutil, flightSkyScanner, datetime, miscUtility, TravelPlanner.startuputil import concurrent, copy logger = loggerUtil.getlogger("FlightBigNearApi") class FlightBigNearAirportController: """ To get flights between source and destination cities, via big airports """ def getresults(self, sourcecity, destinationcity, journeydate, trainclass='3A', flightclass='economy', numberofadults=1): logger.debug("[START]-Get Results From FlightBigNearApi for Source:[%s] to Destination:[%s] on JourneyDate:[%s] ", sourcecity, destinationcity, journeydate) with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: source = TravelPlanner.startuputil.gettraincity(sourcecity).title() destination = TravelPlanner.startuputil.gettraincity(destinationcity).title() airports = flightutil.getnearestairports(source, destination) sourcenear = airports.sourceairports.near sourcebig = airports.sourceairports.big destinationnear = airports.destinationairports.near if sourcenear == destinationnear: logger.warning("Nearest airports to source [%s] and destination [%s] are same [%s]. Hence no flight journey possible", source, destination, sourcenear)
__author__ = 'Hello' import loggerUtil, flightutil, flightSkyScanner,datetime, miscUtility, TravelPlanner.startuputil import concurrent, copy logger = loggerUtil.getlogger("FlightFromBigAirportApi") class FlightFromBigAirportController: """ To get flights between source and destination cities, via big airports """ def getresults(self, sourcecity, destinationcity, journeydate, trainclass='3A', flightclass='economy', numberofadults=1): logger.debug("[START]-Get Results From FlightFromBigAirportApi for Source:[%s] to Destination:[%s] on JourneyDate:[%s] ", sourcecity, destinationcity, journeydate) with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: source = TravelPlanner.startuputil.gettraincity(sourcecity).title() destination = TravelPlanner.startuputil.gettraincity(destinationcity).title() airports = flightutil.getnearestairports(source, destination) sourcenear = airports.sourceairports.near sourcebig = airports.sourceairports.big destinationnear = airports.destinationairports.near destinationbig = airports.destinationairports.big if sourcenear == destinationnear:
from GoIndi import models __author__ = 'ankur' from skyscannerEazzer import Flights import dateTimeUtility import logging import loggerUtil logger = loggerUtil.getlogger("FlighSkyScanner") def getApiResults(sourcecity, destinationcity, journeydate, id, flightClass='Economy', numberOfAdults=1): cityandstatetostationsmap = { 'Jaisalmer': 'JSA', 'Rajahmundry': 'RJA', 'Rajamundry': 'RJA', 'Pantnagar': 'PGH', 'Pathankot': 'IXP', 'Kullu': 'KUU', 'Agartala': 'IXA', 'Agra': 'AGR', 'Ahmedabad': 'AMD', 'Allahabad': 'IXD', 'Amritsar': 'ATQ', 'Aurangabad': 'IXU',
__author__ = 'Hello' import trainConstants, loggerUtil import urllib, json logger = loggerUtil.getlogger("TrainAvailabilityApi") class TrainAvailabilityController: """ To get availability of train between source & destination station on journey date """ def getavailablity(self, trainnumber, sourcestation, destinationstation, journeydate, trainclass, quota='GN'): """ To get availability of train between source & destination station on given date :param trainnumber: number of the train for which we need to check availability :param sourcestation: source station of the journey :param destinationstation: destination station of the journey :param journeydate: date of journey in DD-MM-YYYY format :param trainclass: class of train :param quota: quota of train seat :return: json response containing no. of available seats """ try: url = "http://api.railwayapi.com/check_seat/train/" + trainnumber + "/source/" + sourcestation + "/dest/" + destinationstation + "/date/" + journeydate + "/class/" + trainclass + "/quota/" + quota + "/apikey/" + trainConstants.ERAILWAYAPI_APIKEY + "/"
import busapi import json import urllib2 import flightSkyScanner import concurrent.futures import dateTimeUtility import miscUtility, flightutil import distanceutil import trainapineo4j import minMaxUtil import copy import loggerUtil, models import TravelPlanner.startuputil logger = loggerUtil.getlogger("FlightApi") class FlightController: """Class returns all stations corresponding to a city""" def getresults(self, sourcecity, destinationcity, journeydate, trainclass, flightclass, numberofadults): logger.debug("[START]-Get Results From FlightApi for Source:[%s] and Destination:[%s],JourneyDate:[%s] ",sourcecity,destinationcity,journeydate) with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor: source = TravelPlanner.startuputil.gettraincity(sourcecity).title() destination = TravelPlanner.startuputil.gettraincity(destinationcity).title() # get nearest airport and nearest big airport to our source city url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + source url = url.replace(' ', '%20')