Ejemplo n.º 1
0
	def get_house_results(self):

		zip_code = zipcode.isequal(self.zip)
		d = zip_code.to_dict()
		point = (d['lat'], d['lon'])
		zips = zipcode.isinradius(point, self.radius)
		zips = [new_zip for new_zip in zips if not new_zip.decommisioned != "FALSE"]
		zips = [new_zip.zip for new_zip in zips if new_zip.zip_type == "STANDARD"]

		ads_info = []
		for zip in zips:
			self.bro.driver.get("https://www.zillow.com/homes/for_sale/{0}_rb/house,condo,apartment_duplex,mobile,townhouse_type/?fromHomePage=true&shouldFireSellPageImplicitClaimGA=false&fromHomePageTab=buy".format(zip))

			try:
				next_button = self.bro.driver.find_element_by_xpath("//li[@class='zsg-pagination-next']")
			except:
				next_button = 'Something'

			while next_button:
				ads = self.bro.driver.find_elements_by_xpath("//div[@id='search-results']//article")

				for ad in ads:
					properties = self._get_ad_properties(ad)
					if properties:
						ads_info.extend([properties])

				try:
					next_button = self.bro.driver.find_element_by_xpath("//li[@class='zsg-pagination-next']")
					next_button.click()
				except:
					break
				time.sleep(2)  # Should get rid of this

		self.bro.driver.close()
		write_to_csv("Zillow", ads_info)
Ejemplo n.º 2
0
 def local_city_list_maker(starting_zip='98119', mile_radius=100):
     """returns a set of cities within radius of starting zip,
     formatted with state space city to use in weather_station_code_finder function"""
     zip_obj = zipcode.isequal(starting_zip)
     local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon),
                                     mile_radius)
     return {' '.join([i.state, i.city]) for i in local_zips}
Ejemplo n.º 3
0
def coords2zipcode(latlon, radius=1.5):
    try:
        return zipcode.isinradius(latlon, radius)[0].zip
    except:
        zipcodes = [11232, 10001, 11211, 10026, 11101]
        zipcode = random.sample(zipcodes, 1)[0]
        print(zipcode)
        return zipcode
Ejemplo n.º 4
0
def local_zipcodes(startingzip='98119', radius=10):
    """ Returns zipcodes within radius of startingzip """
    zip_obj = zipcode.isequal(startingzip)
    try:
        local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), radius)
        return [i.zip for i in local_zips]
    except AttributeError:
        return 'No surrounding data available for ' + startingzip
Ejemplo n.º 5
0
def local_city_list_maker(starting_zip='98119', mile_radius=100):
    """returns list of cities within radius of starting zip"""
    city_list = []
    zip_obj = zipcode.isequal(starting_zip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
    for i in local_zips:
        state_city = i.state + ' ' + i.city
        if state_city not in city_list:
            city_list.append(state_city)
    return city_list
Ejemplo n.º 6
0
def local_city_list_maker(starting_zip='98119', mile_radius=100):
    """returns list of cities within radius of starting zip"""
    city_list = []
    zip_obj = zipcode.isequal(starting_zip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
    for i in local_zips:
        state_city = i.state + ' ' + i.city
        if state_city not in city_list:
            city_list.append(state_city)
    return city_list
Ejemplo n.º 7
0
def local_city_grabber(starting_zip='98119', mile_radius=100):
    """returns dict of zipcodes within radius of starting zip"""
    cities = {}
    zip_obj = zipcode.isequal(starting_zip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
    for i in local_zips:
        state_city = i.state + ' ' + i.city
        if state_city not in cities:
            cities[state_city] = {'zip': i.zip}
    return cities
Ejemplo n.º 8
0
def zipcodes_list(st_items):

    # (lat, lon, radius)
    if type(st_items) == tuple:
        zc_objects = zipcode.isinradius(st_items[:2], st_items[2])
        output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
    # If st_items is a single zipcode string.
    elif type(st_items) == str:
        zc_objects = zipcode.islike(st_items)
        output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
    # If st_items is a list of zipcode strings.
    elif type(st_items) == list:
        zc_objects = [n for i in st_items for n in zipcode.islike(str(i))]
        output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
    else:
        raise ValueError("input 'st_items' must be of type str or list")
    return (output)
Ejemplo n.º 9
0
import zipcode
import re

my_zip = zipcode.isequal('98119')
local_zips = zipcode.isinradius((my_zip.lat, my_zip.lon), 100)



zip_dict = {}

## good code!!!
for i in local_zips:
    state_city = i.state + ' ' + i.city
    if state_city not in zip_dict:
        zip_dict[state_city] = [i.zip]
    zip_dict[state_city].append(i.zip)
## good code!!!




print(zip_dict)

code_db = open('weather_codes.txt', 'r').read()

for i in zip_dict:
    #m = re.search('{}.+'.format(i), code_db)
    m = re.search(i + '.*[PKXQ]\w{3}\s\s', code_db)
    #cm = re.search('^[PKXQ]{4}', m.group)
    # m = re.findall(i +'\s^[PKXQ]{4}', code_db)
    try:
Ejemplo n.º 10
0
airbnb_nyc_2b_by_zipcode = airbnb_nyc_2b_by_zipcode[(airbnb_nyc_2b_by_zipcode['rental_data_points_count']>3)]
print("#"*terminal_width)
# join data from zillow
lastest = len(zillow_df.columns) - 1
zillow_df = pd.concat([zillow_df.ix[:,1],zillow_df.ix[:,lastest]], axis=1)
zillow_df.columns = ['RegionName','propertyPrice']
main_df = pd.merge(airbnb_nyc_2b_by_zipcode, zillow_df, left_on = 'zipcode', right_on = 'RegionName', how = 'left')
print main_df.info()
# Since we are going to purchase properties recently, I used the latest price, which is the last column
print "only 18 records with a property price"
print("#"*terminal_width)
# In the following, I will try to match the property price according to adjacent zipcodes
import zipcode
import zipcodes
# estimate the missing property prices
main_df['adjacentZipcodes'] = main_df['zipcode'].map(lambda x: zipcode.isinradius((zipcodes.matching(x)[0]['lat'],zipcodes.matching(x)[0]['long']),1))
# save zipcodes with actual property price into a dict
actualPrices = main_df[['RegionName','propertyPrice']].set_index('RegionName')['propertyPrice'].to_dict()
def f(x):
    res = []
    for i in x:
        if i.zip in actualPrices.keys():
            res.append(actualPrices[i.zip])
    return np.mean(res)

main_df['propertyPrice1st'] = main_df['adjacentZipcodes'].map(f)
main_df['estimatePrice'] = main_df['propertyPrice']
main_df.estimatePrice.fillna(main_df.propertyPrice1st, inplace=True)
print "the number of zip codes with a property price:"
print main_df['estimatePrice'].count()
# 76
Ejemplo n.º 11
0
 def local_city_list_maker(starting_zip='98119', mile_radius=100):
     """returns a set of cities within radius of starting zip,
     formatted with state space city to use in weather_station_code_finder function"""
     zip_obj = zipcode.isequal(starting_zip)
     local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
     return {' '.join([i.state, i.city]) for i in local_zips}
Ejemplo n.º 12
0
def local_city_grabber(starting_zip='98119', mile_radius=100):
    """returns set of cities within radius of starting zip"""
    zip_obj = zipcode.isequal(starting_zip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
    return {'{} {}'.format(i.state, i.city) for i in local_zips}
Ejemplo n.º 13
0
def local_zipcodes(startingzip='98119', radius=100):
    """ Returns zipcodes within radius of startingzip"""
    zip_obj = zipcode.isequal(startingzip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), radius)
    return {i.zip for i in local_zips}
Ejemplo n.º 14
0
def create_dataframe(tweets_data):
    tweets = pd.DataFrame(index=range(len(tweets_data)),
                          columns=[
                              'text', 'created_at', 'location', 'state',
                              'sentiment', 'sentiment_cat', 'country_code',
                              'hour'
                          ])

    for i in range(len(tweets_data)):
        try:
            tweets['text'][i] = tweets_data[i]['text']
        except:
            tweets['text'][i] = ""
        try:
            tweets['location'][i] = tweets_data[i]['user']['location']
        except:
            tweets['location'][i] = 'NA'
        try:
            tweets['country_code'][i] = tweets_data[i]['place']['country_code']
        except:
            tweets['country_code'][i] = ''
        try:
            lon = tweets_data[i]['place']['bounding_box']['coordinates'][0][0][
                0]
        except:
            lon = 'NA'
        try:
            lat = tweets_data[i]['place']['bounding_box']['coordinates'][0][0][
                1]
        except:
            lat = 'NA'
        #print (lat,lon)
        try:
            tweets['created_at'][i] = tweets_data[i]['created_at']
        except:
            tweets['created_at'][i] = 'NA'
        try:
            tweets['hour'][i] = tweets['created_at'][i][11:13]
        except:
            tweets['hour'][i] = 'NA'
        try:
            stateFromData = tweets['location'][i].split(',')[1]
        except:
            stateFromData = ''
        if len(stateFromData) == 2:
            tweets['state'][i] = stateFromData
        else:
            if lat != 'NA':
                radius = 10
                incre = 10
                zips = zipcode.isinradius((lat, lon), radius)
                while len(zips) == 0:
                    radius = radius + incre
                    zips = zipcode.isinradius((lat, lon), radius)
                    incre = incre + 10
                myzip = zipcode.isequal(str(zips[0].zip))
                tweets['state'][i] = myzip.state
            else:
                tweets['state'][i] = 'NA'
        blob = TextBlob(tweets['text'][i])
        try:
            sentence = blob.sentences[0]
            tweets['sentiment'][i] = float(sentence.sentiment.polarity)
        except:
            tweets['sentiment'][i] = 0
        if tweets['sentiment'][i] < 0:
            tweets['sentiment_cat'][i] = 'Neg'
        else:
            if tweets['sentiment'][i] > 0:
                tweets['sentiment_cat'][i] = 'Pos'
            else:
                tweets['sentiment_cat'][i] = 'Neu'
    print(tweets.head())
    return tweets
Ejemplo n.º 15
0
import json
import zipcode
from pprint import pprint

with open('swimmingpools.json') as data_file:
    data = json.load(data_file)

#pprint(data)

myzip = zipcode.isequal('11102')
print myzip.state
print myzip.city.title()

print zipcode.isinradius((40.7788, -73.9227), 2.0)
Ejemplo n.º 16
0
def local_city_grabber(starting_zip='98119', mile_radius=100):
    """returns set of cities within radius of starting zip"""
    zip_obj = zipcode.isequal(starting_zip)
    local_zips = zipcode.isinradius((zip_obj.lat, zip_obj.lon), mile_radius)
    return {'{} {}'.format(i.state, i.city) for i in local_zips}
Ejemplo n.º 17
0
import zipcode
import re

my_zip = zipcode.isequal('98119')
local_zips = zipcode.isinradius((my_zip.lat, my_zip.lon), 100)

zip_dict = {}

## good code!!!
for i in local_zips:
    state_city = i.state + ' ' + i.city
    if state_city not in zip_dict:
        zip_dict[state_city] = [i.zip]
    zip_dict[state_city].append(i.zip)
## good code!!!

print(zip_dict)

code_db = open('weather_codes.txt', 'r').read()

for i in zip_dict:
    #m = re.search('{}.+'.format(i), code_db)
    m = re.search(i + '.*[PKXQ]\w{3}\s\s', code_db)
    #cm = re.search('^[PKXQ]{4}', m.group)
    # m = re.findall(i +'\s^[PKXQ]{4}', code_db)
    try:
        print(m.group())
        cm = re.search('\s[PKXQ]\w{3}\s\s', m.group())
        print(cm.group())
    # print(m.groups())
    except: