def flight(name): typ = flightUtil.flightType(name) query = '' if typ=="direct": query = flightUtil.directFlightPriceHistoryQuery elif typ=="oneStop": query = flightUtil.oneStopFlightPriceHistoryQuery elif typ=="twoStop": query = flightUtil.twoStopFlightPriceHistoryQuery priceHistory = flightUtil.executeQueryAndReturn( query%name) print priceHistory priceHistory = [(price[0],price[1]) for price in priceHistory] history ='' p = '' print priceHistory for i in range(len(priceHistory)): p = priceHistory[i][0] dt = str(priceHistory[i][1]) print dt dt = dt.split('/') history += dt[0]+' '+dt[1]+' '+dt[2]+' ' history += str(priceHistory[i][0])+';' history += (flightUtil.currentDate())+' ' history += str(p) print history return history
def priceHistory(): slotFrom='Select' slotTo='Select' origin='Select' originValue='' destination='Select' destinationValue='' date='' metrics=['MIN','AVG','MAX'] metric='Select' history=[] try: cities = flightUtil.executeQueryAndReturn(flightUtil.cityQuery) if request.method=='POST': slotFrom=request.form['selectedSlotFrom'] slotTo=request.form['selectedSlotTo'] origin=request.form['selectedOrigin'] destination=request.form['selectedDestination'] date=request.form['datepicker'] metric=request.form['selectedMetric'] query = flightUtil.metricPriceHistoryQuery%(\ metric,\ slotFrom,\ slotTo,\ origin,\ destination,\ origin+'%'+flightUtil.flightQuerySufix(date)+'%') print query history=flightUtil.executeQueryAndReturn(query) print history priceHistory = [(hist[0],hist[1]) for hist in history] print priceHistory history ='' p = '' for i in range(len(priceHistory)): p = priceHistory[i][1] dt = str(priceHistory[i][0]) print dt dt = dt.split('/') history += dt[2]+' '+dt[1]+' '+dt[0]+' ' history += str(p)+':' history += (flightUtil.currentDate())+' ' history += str(p) print history originValue = origin destinationValue = destination destination = flightUtil.executeQueryAndReturn(\ flightUtil.cityNameQuery%(destination))[0][0] origin = flightUtil.executeQueryAndReturn(\ flightUtil.cityNameQuery%(origin))[0][0] except Exception, e: print 'Error occured'+str(e) return render_template('error.html',error=str(e))