def get_cached_sql_result_as_dict(sql,db_conn):
    if db_conn['db_type'] not in ('sql_server','mysql'):
        raise Error('db_type error')
    unique_key=helper_math.md5(','.join(sorted(db_conn.values()))+sql)

    cached_result=helper_mysql.get_dict_of_raw_collection_from_key(oem_name='',category='', key='',\
                                sub_key=unique_key,date='',table_name='raw_data_cache_sql_result',db_conn=None)

    if cached_result:
        print 'get from cache:',unique_key
        return cached_result
    
    if db_conn['db_type']=='sql_server':
        cached_result=helper_sql_server.fetch_dict(conn_config=db_conn,sql=sql)
    else:
        cached_result=helper_mysql.fetch_dict(db_conn=db_conn,sql=sql)

    helper_mysql.put_collection_with_value(collection=cached_result,oem_name='',category='',key='',sub_key=unique_key, \
                                table_name='raw_data_cache_sql_result',date='',created_on=None,db_conn=None)
    
    print 'push into cache:',unique_key
    return cached_result
Exemplo n.º 2
0
sys.stdout = open(os.devnull, "w")

try:
    form = cgi.FieldStorage()

    table = form.getvalue("table", "raw_data")
    oem_name = form.getvalue("oem_name", "Mozat")
    category = form.getvalue("category", "moagent")
    key = form.getvalue("key", "app_page_only_ais_hourly_visitor_unique_collection_id")
    sub_key = form.getvalue("sub_key", "")
    date_start = form.getvalue("date_start", "2012-04-03 00")
    date_end = form.getvalue("date_end", "2012-04-16 23")
    sign = form.getvalue("sign", "")

    signed_key = ",".join([table, oem_name, category, key, sub_key, date_start, date_end, config.url_sign_key])
    expected_sign = helper_math.md5(signed_key)

    if expected_sign != sign:
        content = "Auth Failed. Don't try to modify the download url."
    else:
        sql = r"""
            select `value`
            from %s
            where oem_name='%s'
            and category='%s'
            and `key`='%s'
            and sub_key='%s'
            and date>='%s'
            and date<='%s'
        """ % (
            table,