Example #1
0
class ConnectionChecker(object):
    def __init__(self, vayant_connector):
        self.flight_checker = FlightChecker(vayant_connector)
        self.flights_resp_dal = FlightsRespDAL()
        self.resp_collector = ResponseCollector()

    def get_dict_key(self, origin, dest, depart_date, return_date):
        return "%s-%s, %s, %s" % (origin, dest, depart_date, return_date)

    def run_connection_check_async(self, origin, dest, depart_date, return_date):
        area = self.flights_resp_dal.get_area_code(origin, dest)
        connections_list = self.flights_resp_dal.get_connections_in_area(area)

        if len(connections_list) == 0:
            print "couldn't get connection list"
            return None

        for single_connection in connections_list[0]:
            if origin != dest != single_connection != origin:
                async_response = self.flight_checker.run_test_list(origin, dest, depart_date, return_date, single_connection, None)
                self.resp_collector.add_response(single_connection, "first", async_response)

        return AsyncMultiResponse(self.resp_collector)

    def run_connection_check(self, origin, dest, depart_date, return_date):
        dict_key = self.get_dict_key(origin, dest, depart_date, return_date)
        cached_result = self.flights_resp_dal.get_results(dict_key)

        if cached_result:
            return cached_result

        async_resp = self.run_connection_check_async(origin, dest, depart_date, return_date)
        res = async_resp.get_response()

        dict_key = self.get_dict_key(origin, dest, depart_date, return_date)
        self.flights_resp_dal.insert_results_to_db(dict_key, res)

        return res
import pickle
import datetime
from db.flights_resp import FlightsRespDAL
from random import randint
import pickle

TESTS_TO_CREATE = 10000

flights_resp_dal = FlightsRespDAL()

airports = flights_resp_dal.get_all_airports()

tests = []
for index in xrange(0, TESTS_TO_CREATE):
    origin = airports[randint(0, len(airports)-1)]
    dest = airports[randint(0, len(airports)-1)]
    departure_date = datetime.date(2014, 8, 22) + datetime.timedelta(days=randint(0,130))
    return_date = departure_date+ datetime.timedelta(days=randint(5,40))

    tests.append((origin, dest, departure_date, return_date))


with open("tests.info", "w") as tests_file:
    for test in tests:
        pickle.dump(test,tests_file)

Example #3
0
 def __init__(self, vayant_connector):
     self.flight_checker = FlightChecker(vayant_connector)
     self.flights_resp_dal = FlightsRespDAL()
     self.resp_collector = ResponseCollector()
from db.flights_resp import FlightsRespDAL
from flights_data2.constants import *

if __name__ == "__main__":
    flights_resp_dal = FlightsRespDAL()

    connections_by_areas = flights_resp_dal.connections_collection.find()


    for area1 in areas:
        for area2 in areas:
            key = "%s-%s" % (area1[1], area2[1])
            connections = flights_resp_dal.get_connections_in_area(key)

            print "----------------------------"
            print "connections for flights from {} to {}".format(area1[2], area2[2])
            if connections:
                for connection in connections:
                    airport = flights_resp_dal.get_airport(connection)
                    if airport:
                        print "code = {}, airport = {}, country = {}".format(connection, airport[0], airport[1])
                    else:
                        print "unknown details for airport code {}".format(connection)