コード例 #1
0
ファイル: geo.py プロジェクト: tfgg/cvn.org
def constituency(place):
    try:
        if POSTCODE_RE.match(place):
            return twfy.getConstituency(place)
        else:
            _, (lat, lng) = geocode(place)
            consts = twfy.getConstituencies(latitude=lat, longitude=lng, distance=10)
            if len(consts) > 0:
                return consts[0]
    except Exception:
        return None
コード例 #2
0
def constituency(place):
    try:
        if POSTCODE_RE.match(place):
            return twfy.getConstituency(place)
        else:
            _, (lat, lng) = geocode(place)
            consts = twfy.getConstituencies(latitude=lat,
                                            longitude=lng,
                                            distance=10)
            if len(consts) > 0:
                return consts[0]
    except Exception:
        return None
コード例 #3
0
def constituency(place):
    try:
        if POSTCODE_RE.match(place):
            const = twfy.getConstituency(place)
            if const == None:
                return None
            else:
                return [const]
        else:
            _, (lat, lng) = geocode(place)
            
            consts = None
            distance = 10
            while not consts:
                # Only likely to actually loop in extreme, circumstances,
                # e.g. "Haltwhistle". See issue 19
                consts = twfy.getConstituencies(latitude=lat,
                                                longitude=lng,
                                                distance=distance)
                distance = distance * 2
            
            return [x['name'] for x in consts]
    except Exception:
        return None