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])
fig = plt.figure() ax = fig.add_subplot(111) for m in xrange(len(grey_plot)): ax.plot_date(dates_expedia[m], smooth_expedia[m][mask_expedia[m]], fmt='-', marker='o',markersize=3,color='#58ACFA',markeredgecolor='#58ACFA', tz=None, xdate=True, ydate=False) ax.plot_date(dates_kayak[m], smooth_kayak[m][mask_kayak[m]], fmt='-', marker='o',markersize=3,color='#F7BE81',markeredgecolor='#F7BE81', tz=None, xdate=True, ydate=False) ax.plot_date(dates_expedia[0], smooth_expedia[0][mask_expedia[0]], fmt='-', marker='o',markersize=3,color='#58ACFA',markeredgecolor='#58ACFA', tz=None, xdate=True, ydate=False,label="fares for flights on expedia" ) ax.plot_date(dates_kayak[0], smooth_kayak[0][mask_kayak[0]], fmt='-', marker='o',markersize=3,color='#F7BE81',markeredgecolor='#F7BE81', tz=None, xdate=True, ydate=False, label="fares for flights on kayak" ) ax.plot_date(filtered_searchtimes, filtered_fares, fmt=':',color="#009999", linewidth=3, dashes=(20,20), tz=None, xdate=True, ydate=False) ax.plot_date(alertdate,alertfare, fmt='o',color="#009999",markeredgecolor='#009999', markersize=12, tz=None,xdate=True, ydate=False) dateFmt = mpl.dates.DateFormatter('%m/%d') ax.xaxis.set_major_formatter(dateFmt) fig.autofmt_xdate(bottom=0.18) # adjust for date labels display FGname=fbf.get_flightgroup_name(fgid) #PlotTitle='$'+str(fares[-1])+' for '+FGname+' on '+website[-1]+' between '+str(dateA[-1].month)+'/'+str(dateA[-1].day)+' and '+str(dateB[-1].month)+'/'+str(dateB[-1].day) #title(PlotTitle) xlabel('month/day') ylabel('Ticket price (USD)') vax1=[min(search_times),max(search_times),min(filtered_fares)*0.95,max(filtered_fares)*1.3] ax.legend() ax.axis(vax1) filename = home+'/static/plots/'+str(fgid)+'b.png' savefig(filename, dpi=mydpi) plt.clf() print "created", filename time.sleep(wait_time)