Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description='Get the data from data.sfgov on food trucks and populate the db with it.')
    parser.add_argument('-u','--url', help='The database url to populate', required=True)
    args = vars(parser.parse_args())

    food_truck_db = args['url']
    
    truck_request = requests.get('http://data.sfgov.org/resource/rqzj-sfat.json')

    if truck_request.status_code != 200:
        raise Exception("Error getting data. Status code: %s, Message: %s" % truck_request.status, truck_request.data)

    truck_list = json.loads(truck_request.content)
    engine = get_engine(food_truck_db)
    session = get_db_session(engine)

    session.query(FoodTruck).delete()

    for t in truck_list:
        print t['applicant']
        try:
            new_truck = FoodTruck(t['applicant'], t['location']['latitude'], t['location']['longitude'])
            new_truck.fooditems = t['fooditems']
            session.add(new_truck)

            session.commit()
        except flask_sqlalchemy.sqlalchemy.exc.IntegrityError:
            session.rollback()
            continue
        except KeyError:
            continue
    def setUp(self):
        test_sql = 'sqlite:///test_db.sql'
        self.engine = get_engine(test_sql)
        self.db = init_db(self.engine, Base)
        self.db_session = get_db_session(self.engine)
        my_app.config['DB_SESSION'] = self.db_session

        self.app = my_app.test_client()
    def setUp(self):
        test_sql = 'sqlite:///test_db.sql'
        self.engine = get_engine(test_sql)
        self.db = init_db(self.engine, Base)
        self.db_session = get_db_session(self.engine)
        my_app.config['DB_SESSION'] = self.db_session

        self.app = my_app.test_client()
Exemple #4
0
def run_server():
    parser = argparse.ArgumentParser(description='Create the data base for the food truck app.')
    parser.add_argument('-u','--url', help='The database url to create', required=True)
    args = vars(parser.parse_args())

    food_truck_db = args['url']
    
    from food_trucks.db import get_engine, get_db_session
    engine = get_engine(food_truck_db)
    my_app.config['DB_SESSION'] = get_db_session(engine)
    define_urls(my_app)
    my_app.debug = True
    return my_app
Exemple #5
0
def run_server():
    parser = argparse.ArgumentParser(
        description='Create the data base for the food truck app.')
    parser.add_argument('-u',
                        '--url',
                        help='The database url to create',
                        required=True)
    args = vars(parser.parse_args())

    food_truck_db = args['url']

    from food_trucks.db import get_engine, get_db_session
    engine = get_engine(food_truck_db)
    my_app.config['DB_SESSION'] = get_db_session(engine)
    define_urls(my_app)
    my_app.debug = True
    return my_app
Exemple #6
0
 def setUp(self):
     # self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     test_sql = 'sqlite:///test_db.sql'
     self.engine = get_engine(test_sql)
     self.db = init_db(self.engine, Base)
     self.db_session = get_db_session(self.engine)
 def setUp(self):
     # self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     test_sql = 'sqlite:///test_db.sql'
     self.engine = get_engine(test_sql)
     self.db = init_db(self.engine, Base)
     self.db_session = get_db_session(self.engine)