コード例 #1
0
def map_breweries_for_country(db, rb_id, iso_code):
    breweries_osm = get_osm_breweries('NO')
    breweries_rb = db.get_rb_breweries_for_country(rb_id)
    brewery_matcher = BreweryNameMatcher(breweries_rb)
    matches = []
    for brewery in breweries_osm['features']:
        props = brewery['properties']
        match = brewery_matcher.match_name(unicode(props['operator']))
        if match is None:
            match = brewery_matcher.match_name(unicode(props['name']))
        add = {
            'osm_id': brewery['id'],
            'ratebeer_id': None,
            'website': props['website'],
            'amenity': props['amenity'],
            'housenumber': props['housenumber'],
            'city': props['city'],
            'postcode': props['postcode'],
            'street': props['street'],
            'country': props['country'],
            'name': props['name'],
            'operator': props['operator'],
            'geom': json.dumps(brewery['geometry'])
        }
        if match is not None:
            add['ratebeer_id'] = match['id']
        matches.append(add)

    return matches
コード例 #2
0
# -*- coding: utf-8 -*-
import sys
import json
import os

from beertools import get_osm_breweries


if __name__ == '__main__':
    country = sys.argv[1]
    outfile = sys.argv[2]

    path = os.path.join(os.getcwd(), outfile)
    with open(path, 'w') as out:
        breweries = get_osm_breweries(country)
        out.write(json.dumps(breweries, indent=4))