Example #1
0
def get(code):
    db = mongo.get_db()
    variable = db.variables.find_one({'code': code})
    if (not variable) or config.bool('reload'):
        logging.info("Variable %s not found, loading from SOAP...", code)
        variable = soap.get_variable(code)
        if not variable: 
            return None
        for link in variable.get('links', []):
            if u"Tabellen mit Vorkommen des Merkmals" in link.get('titel'):
                variable['tables'] = [t for t in load_variable_tables(link.get('href'))]
        variable['__ts'] = datetime.utcnow()
        db.variables.update({'code': code}, variable, upsert=True)
    return variable
Example #2
0
def get(table_id):
    db = mongo.get_db()
    table = db.tables.find_one({'code': table_id})
    if (not table) or config.bool('reload'):
        logging.info("Table %s not found, loading from SOAP...", table_id)
        table_data = soap.get_table(table_id)
        if not table_data:
            return None
        get_data(table_id)
        table = {'csvdata': table_data, 'code': table_id}
        table.update(table_to_dict(table_id, table_data))
        db.tables.update({'code': table_id}, table, upsert=True)
    else:
        reparse_table(table_id)
    return table
Example #3
0
def get(table_id):
    db = mongo.get_db()
    table = db.tables.find_one({'code': table_id})
    if (not table) or config.bool('reload'):
        logging.info("Table %s not found, loading from SOAP...", table_id)
        table_data = soap.get_table(table_id)
        if not table_data: 
            return None
        get_data(table_id)
        table = {'csvdata': table_data, 'code': table_id}
        table.update(table_to_dict(table_id, table_data))
        db.tables.update({'code': table_id}, table, upsert=True)        
    else:
        reparse_table(table_id)
    return table
Example #4
0
def get(code):
    db = mongo.get_db()
    variable = db.variables.find_one({'code': code})
    if (not variable) or config.bool('reload'):
        logging.info("Variable %s not found, loading from SOAP...", code)
        variable = soap.get_variable(code)
        if not variable:
            return None
        for link in variable.get('links', []):
            if u"Tabellen mit Vorkommen des Merkmals" in link.get('titel'):
                variable['tables'] = [
                    t for t in load_variable_tables(link.get('href'))
                ]
        variable['__ts'] = datetime.utcnow()
        db.variables.update({'code': code}, variable, upsert=True)
    return variable
Example #5
0
def get(stat_id, include_tables=True):
    db = mongo.get_db()
    statistic = db.statistics.find_one({'code': stat_id})
    if (not statistic) or config.bool('reload'):
        logging.info("Statistic %s not found, loading from SOAP...", stat_id)
        statistic = soap.get_statistic(stat_id)
        if not statistic: 
            return None
        tables = []
        for table in soap.find_tables_by_statistic(stat_id):
            tables.append(table)
        statistic['tables'] = tables
        statistic['description'] = load_description(stat_id)
        statistic['variables'] = [v for v in load_variables(stat_id)]
        statistic['__ts'] = datetime.utcnow()
        db.statistics.update({'code': stat_id}, statistic, upsert=True)
    import table
    for _table in statistic['tables']:
        table.get(_table.get('code'))
    return statistic
Example #6
0
def load_cached(**kwargs):
    if config.bool('cache'):
        kwargs['section'] = config.section()
        data = get_db().loadcache.find_one(kwargs)
        if data:
            return data.get('__data', {})
Example #7
0
def load_cached(**kwargs):
    if config.bool("cache"):
        kwargs["section"] = config.section()
        data = get_db().loadcache.find_one(kwargs)
        if data:
            return data.get("__data", {})