#If days until flight > 100 and Days monitoring > 10, alert if price is lower or equal than lowest No->(or 30% less than average). if ((DaysUntilFlight > 100.) and (DaysMonitoring > 10.) and (fares[-1] <= LowestPrice)): fbf.write_groupfare(datetime.datetime.utcnow(),fgid,fids[-1],fares[-1],website[-1],search_times[-1],1) #If days until flight < 100 and Days monitoring > 3, alert if price is lower than lowest (or 30% less than average). if ((DaysUntilFlight < 100.) and (DaysMonitoring > 3.) and (fares[-1] <= LowestPrice)): fbf.write_groupfare(datetime.datetime.utcnow(),fgid,fids[-1],fares[-1],website[-1],search_times[-1],1) if(totflags > 0.5): DaysSinceAlert=fbf.days_since_last_alert(fgid) BestPriceOfLastWeek=fbf.min_fare_within_last_week(fgid) LastAlertPrice=fbf.fare_of_last_alert(fgid) #If last suggestion was less than 5 days ago only suggest again if price is >5% lower than suggestion. if ((DaysSinceAlert < 5.) and (fares[-1] <= (0.95*LastAlertPrice))): fbf.write_groupfare(datetime.datetime.utcnow(),fgid,fids[-1],fares[-1],website[-1],search_times[-1],1) #If last suggestion was more than 5 days ago buy less 14 days ago suggest price suggest if price is lower or equal than last suggestion. if ((DaysSinceAlert > 5.) and (DaysSinceAlert < 14.) and (fares[-1] <= LastAlertPrice)): fbf.write_groupfare(datetime.datetime.utcnow(),fgid,fids[-1],fares[-1],website[-1],search_times[-1],1) #If last suggestion was more than 14 days ago, suggest if price is lower than the lowest in the past 7 days. if ((DaysSinceAlert > 14.) and (fares[-1] <= BestPriceOfLastWeek)): fbf.write_groupfare(datetime.datetime.utcnow(),fgid,fids[-1],fares[-1],website[-1],search_times[-1],1)
def check_flights(): user_table=wf.get_user_table() user=str(request.args.get("user",None)) uid_index=user_table[1].index(user) uid=user_table[0][uid_index] fgids=wf.get_gfids(uid) trips=[] embryos=[] born_fgids=[] embryo_fgids=[] for fgid in fgids: try: with open('static/plots/'+str(fgid)+'a.png'): born_fgids.append(fgid) print fgid, "born" except IOError: embryo_fgids.append(fgid) print fgid, "embryo" for fgid in born_fgids: graph1=str(fgid)+"a.png" graph2=str(fgid)+"b.png" graph3=str(fgid)+"c.png" FGname=fbf.get_flightgroup_name(fgid) (group_times,search_times,fares,website,alert,dateA,dateB,fid)=fbf.get_best_timeseries(fgid) (portA,portB)=fbf.get_flightgroup_ports(fgid) fare_of_last_alert=int(fbf.fare_of_last_alert(fgid)) days_since_last_alert=int(fbf.days_since_last_alert(fgid)) min_fare_within_last_week=int(fbf.min_fare_within_last_week(fgid)) avg_fare_within_last_week=int(fbf.avg_fare_within_last_week(fgid)) if(days_since_last_alert > 999): days_since_last_alert='N/A' fare_of_last_alert='N/A' dayA=("%02d" %dateA[-1].day) monthA=("%02d" %dateA[-1].month) yearA=("%02d" %(dateA[-1].year-2000)) dayB=("%02d" %dateB[-1].day) monthB=("%02d" %dateB[-1].month) yearB=("%02d" %(dateB[-1].year-2000)) expedia_url="http://www.expedia.com/pub/agent.dll?qscr=fexp&flag=q&city1="+portA+"&citd1="+portB+"&date1="+monthA+"/"+dayA+"/20"+yearA+"&time1=362&date2="+monthB+"/"+dayB+"/20"+yearB+"&time2=362&cAdu=1&cSen=&cChi=&cInf=&infs=2&tktt=&trpt=2&ecrc=&eccn=&qryt=8&load=1&airp1=&dair1=&rdct=1&rfrr=-429" bing_url="http://www.bing.com/travel/flights/search?q=&vo1=%28"+portA+"%29&o="+portA+"&ve1=%28"+portB+"%29&e="+portB+"&d1="+monthA+"%2F"+dayA+"%2F20"+yearA+"&r1="+monthB+"%2F"+dayB+"%2F20"+yearB+"&p=1&b=COACH" if(website[-1] == 'expedia'): gourl=expedia_url else: gourl=bing_url flightgroup_to_check=fbf.read_flightgroups(fgid) lastflight=fbf.latest_departure(int(flightgroup_to_check[5]), int(flightgroup_to_check[6]), int(flightgroup_to_check[7]), int(flightgroup_to_check[8]), int(flightgroup_to_check[9]), int(flightgroup_to_check[10]), int(flightgroup_to_check[11]), int(flightgroup_to_check[12]), int(flightgroup_to_check[13]), int(flightgroup_to_check[14]), int(flightgroup_to_check[15]), int(flightgroup_to_check[16]), int(flightgroup_to_check[17]), int(flightgroup_to_check[18]), int(flightgroup_to_check[19]), int(flightgroup_to_check[20]), int(flightgroup_to_check[21]), int(flightgroup_to_check[22]), int(flightgroup_to_check[23]), int(flightgroup_to_check[24])) DaysUntilFlight=float(date2num(lastflight[0]))-float(date2num(datetime.datetime.utcnow())) trip_to_show=[gourl,graph1,graph2,graph3,portA,portB,FGname,fares[-1],fare_of_last_alert,days_since_last_alert,avg_fare_within_last_week, min_fare_within_last_week,int(DaysUntilFlight)] trips.append(trip_to_show) for fgid in embryo_fgids: FGname=fbf.get_flightgroup_name(fgid) (portA,portB)=fbf.get_flightgroup_ports(fgid) embryo_to_show=[FGname,portA,portB] embryos.append(embryo_to_show) if (len(born_fgids)==0 and len(embryo_fgids)==0): user_approval='Awaiting administrator approval for '+user+'.' else: user_approval='' return render_template("check_flights.html",trips=trips,embryos=embryos,user_approval=user_approval,users=user_table[1])
and (fares[-1] <= LowestPrice)): fbf.write_groupfare(datetime.datetime.utcnow(), fgid, fids[-1], fares[-1], website[-1], search_times[-1], 1) #If days until flight < 100 and Days monitoring > 3, alert if price is lower than lowest (or 30% less than average). if ((DaysUntilFlight < 100.) and (DaysMonitoring > 3.) and (fares[-1] <= LowestPrice)): fbf.write_groupfare(datetime.datetime.utcnow(), fgid, fids[-1], fares[-1], website[-1], search_times[-1], 1) if (totflags > 0.5): DaysSinceAlert = fbf.days_since_last_alert(fgid) BestPriceOfLastWeek = fbf.min_fare_within_last_week(fgid) LastAlertPrice = fbf.fare_of_last_alert(fgid) #If last suggestion was less than 5 days ago only suggest again if price is >5% lower than suggestion. if ((DaysSinceAlert < 5.) and (fares[-1] <= (0.95 * LastAlertPrice))): fbf.write_groupfare(datetime.datetime.utcnow(), fgid, fids[-1], fares[-1], website[-1], search_times[-1], 1) #If last suggestion was more than 5 days ago buy less 14 days ago suggest price suggest if price is lower or equal than last suggestion. if ((DaysSinceAlert > 5.) and (DaysSinceAlert < 14.) and (fares[-1] <= LastAlertPrice)): fbf.write_groupfare(datetime.datetime.utcnow(), fgid, fids[-1], fares[-1], website[-1], search_times[-1], 1)