Example #1
0
def generateQueries(spaceQuery):    
    """Generates queries for get in mongo"""
    Q = {}
    if isinstance(spaceQuery,list) or isinstance(spaceQuery,tuple):
        for x in uniqify(spaceQuery):
            Q[tuple(x.split('.'))] = {'$exists':True}
    
    elif hasattr(spaceQuery,'keys'):
        spaceQuery = convertSQ(spaceQuery)
        for x in spaceQuery.keys():
            Q[tuple(x.split('.'))] = spaceQuery[x]
            
    return Q
Example #2
0
def SpaceComplete(x):
    """FIPS -> names and upwards when possible"""
    if 'f' in x.keys():
        x = x.copy()
        iFIPS = ListUnion([SPACE_HIERARCHY_R[c] for c in x['f'].keys()])
        iFIPS = [c for c in iFIPS if c not in x.keys()]
        Cset = [c + '=' + x['f'][c] for c in x['f'].keys() if uniqify(x['f'][c]) != ['0']]
        if iFIPS and Cset:
      
            X = eval(urllib2.urlopen('http://localhost:8000/geo/fips/?' + '&'.join(Cset)).read())
            if len(X) == 1:
                X = convertToCodes(X[0])
                x['f'] = X['f']
                for c in X.keys():
                    if c not in x.keys():
                        x[c] = X[c]
            
    return x