def getNearbyZips(targetZip, searchRad):
    clean_list = []
    zipcodeDB = pyzipcode.ZipCodeDatabase()
    zipResults = [z.zip for z in zipcodeDB.get_zipcodes_around_radius(targetZip, searchRad)]
    return zipResults
示例#2
0
    "GEOIP_ASN_DATABASE_FILE")
if not app.config.get("GEOIP_ASN_DATABASE_FILE"):
    app.config["GEOIP_ASN_DATABASE_FILE"] = os.getenv(
        'GEOIP_ASN_DATABASE_FILE', 'data/GeoLite2-ASN.mmdb')

app.config["GEOIP_CITY_DATABASE_FILE"] = cfg_settings.Cfg_settings.get_setting(
    "GEOIP_CITY_DATABASE_FILE")
if not app.config.get("GEOIP_CITY_DATABASE_FILE"):
    app.config["GEOIP_CITY_DATABASE_FILE"] = os.getenv(
        'GEOIP_CITY_DATABASE_FILE', 'data/GeoLite2-City.mmdb')

GEOIP_ASN_DATABASE_FILE = app.config["GEOIP_ASN_DATABASE_FILE"]
GEOIP_CITY_DATABASE_FILE = app.config["GEOIP_CITY_DATABASE_FILE"]
ASN_READER = geoip2.database.Reader(GEOIP_ASN_DATABASE_FILE)
CITY_READER = geoip2.database.Reader(GEOIP_CITY_DATABASE_FILE)
ZIPCODE_DB = pyzipcode.ZipCodeDatabase()


def get_geo_for_ip(ip_address):
    try:
        ip_address = IPAddress(ip_address)
        if not ip_address.is_private:
            asn_info = ASN_READER.asn(ip_address)
            city_info = CITY_READER.city(ip_address)
            zip_code = city_info.postal.code
            return dict(ip=ip_address,
                        asn=asn_info.autonomous_system_organization,
                        country_code=city_info.country.iso_code,
                        city=city_info.city.names["en"]
                        if city_info.city.names else None,
                        zip_code=zip_code,
示例#3
0
 def setUp(self):
     self.db = pyzipcode.ZipCodeDatabase()
import numpy as np
import json
import operator
import csv
import re
import pyzipcode

zcdb = pyzipcode.ZipCodeDatabase()


class YelpScoring(object):
    def __init__(self):
        self.data = self.create_python_dict()
        self.restaurants = self.data[0]
        self.restaurant_dict = self.data[1]
        self.zipcodes = self.data[2]

    def create_python_dict(self):
        """ Converts json (the yelp data set) to a list of restaurants and python 
    dictionary to be used throughout the program.
    
    Returns: a tuple (list with each element as restaurant dictionary, python 
    dictionary with business id of restaurant as key and the restaurant dictionary as value)
    """

        tempList = []
        tempDict = {}
        zipcodes = set()

        with open('yelp-restaurants.txt') as f:
            for jsonObj in f.readlines():