@app.route('/raw/')
def query_raw_data():
    query_parameters = request.args
    product_name = query_parameters.get('product_name')
    market_name = query_parameters.get('market_name')
    country_code = query_parameters.get('country_code')
    source_name = query_parameters.get('source_name')
    labs_conn = psycopg2.connect(user=os.environ.get('aws_db_user'), password=os.environ.get('aws_db_password'), host=os.environ.get('aws_db_host'), port=os.environ.get('aws_db_port'), database=os.environ.get('aws_db_name'))
    labs_curs = labs_conn.cursor()
    if source_name:
        labs_curs.execute('\n                    SELECT id\n                    FROM sources\n                    WHERE source_name = %s\n        ', (source_name,))
        source_id = labs_curs.fetchall()
        if (not source_id):
            return 'That source name is not in the db.'
        else:
            source_id = source_id[0][0]
    query = ' \n            SELECT *\n            FROM raw_table\n            WHERE\n            '
    to_filter = []
    if product_name:
        query += ' product_name=%s AND'
        to_filter.append(product_name)
    if (market_name and country_code):
        market_id = ((market_name + ' : ') + country_code)
        query += ' market_id=%s AND'
        to_filter.append(market_id)
    if source_name:
        labs_curs.execute('\n                SELECT id\n                FROM sources\n                WHERE source_name = %s\n        ', (source_name,))
        source_id = labs_curs.fetchall()
        if source_id:
            source_id = source_id[0][0]
            query += ' source_id = %s AND'
            to_filter.append(source_id)
    if (not (product_name and market_name and country_code)):
        return page_not_found(404)
    query = (query[:(- 4)] + ';')
    labs_curs.execute(query, to_filter)
    result = labs_curs.fetchall()
    if result:
        return jsonify(result)
    else:
        return page_not_found(404)
    if labs_conn:
        labs_conn.close()
@app.route('/raw/')
def query_raw_data():
    query_parameters = request.args
    product_name = query_parameters.get('product_name')
    market_name = query_parameters.get('market_name')
    country_code = query_parameters.get('country_code')
    source_name = query_parameters.get('source_name')
    labs_conn = psycopg2.connect(user=os.environ.get('aws_db_user'), password=os.environ.get('aws_db_password'), host=os.environ.get('aws_db_host'), port=os.environ.get('aws_db_port'), database=os.environ.get('aws_db_name'))
    labs_curs = labs_conn.cursor()
    if source_name:
        labs_curs.execute('\n                    SELECT id\n                    FROM sources\n                    WHERE source_name = %s\n        ', (source_name,))
        source_id = labs_curs.fetchall()
        if (not source_id):
            return 'That source name is not in the db.'
        else:
            source_id = source_id[0][0]
    query = ' \n            SELECT *\n            FROM raw_table\n            WHERE\n            '
    to_filter = []
    if product_name:
        query += ' product_name=%s AND'
        to_filter.append(product_name)
    if (market_name and country_code):
        market_id = ((market_name + ' : ') + country_code)
        query += ' market_id=%s AND'
        to_filter.append(market_id)
    if source_name:
        labs_curs.execute('\n                SELECT id\n                FROM sources\n                WHERE source_name = %s\n        ', (source_name,))
        source_id = labs_curs.fetchall()
        if source_id:
            source_id = source_id[0][0]
            query += ' source_id = %s AND'
            to_filter.append(source_id)
    if (not (product_name and market_name and country_code)):
        return page_not_found(404)
    query = (query[:(- 4)] + ';')
    labs_curs.execute(query, to_filter)
    result = labs_curs.fetchall()
    if result:
        return jsonify(result)
    else:
        return page_not_found(404)
    if labs_conn:
        labs_conn.close()