-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.py
executable file
·146 lines (119 loc) · 5.27 KB
/
scrape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
import json
import requests
from datetime import datetime, timedelta
class IrvineApartments:
def __init__(self, community_name=None, property_name=None, plan_name=None):
self.apartment_ids = 'apartment_ids.json'
self.api_floorplan_url = 'https://www.irvinecompanyapartments.com/snp'
self.api_floorplan_pricing_url = 'https://www.irvinecompanyapartments.com/bin/tic/ica/floorplanpricingavailability'
self.community_name = community_name
self.plan_name = plan_name
self.property_name = property_name
self.id_string = self._gen_id_string(community_name=self.community_name, property_name=self.property_name)
self.guid = self._get_floorplan_guids(plan_name=self.plan_name)
self.available_apartments = self._get_floorplan_pricing()
def _gen_id_string(self, community_name=None, property_name=None):
try:
with open(self.apartment_ids) as f:
apartments = json.loads(f.read())
except Exception as e:
print(e, file=stderr)
exit(1)
id_string = []
for community in apartments:
for property in apartments[community]:
if community_name and community_name == community:
if property_name and property_name == property:
id_string.append(apartments[community][property])
else:
id_string.append(apartments[community][property])
else:
id_string.append(apartments[community][property])
return id_string
def _get_floorplan_guids(self, plan_name=None):
payload = {
'app': 'ica',
'count': '999',
'sp_s': 'planName',
'sp_x_1': 'appId',
'sp_q_1': 'ica',
'sp_x_2': 'entityType',
'sp_q_2': 'floorplan',
'sp_x_3': 'propertyIdCRM',
'sp_q_exact_3': '|'.join(self.id_string)
}
try:
result = requests.get(self.api_floorplan_url, params=payload)
except Exception as e:
print(e, file=stderr)
exit(1)
data = result.json()
guid = {}
for resultset in data['resultsets']:
for result in resultset['results']:
if plan_name and result['planName'] == plan_name:
guid[result['communityIdAEM']] = result['floorUnitTypeCode']
elif plan_name is None:
guid[result['communityIdAEM']] = result['floorUnitTypeCode']
return guid
def _get_floorplan_pricing(self):
now = datetime.now()
# the website expects 424 days (425 if leap year) added to the current date (roughly 14 months)
if self._is_leap_year(now.year):
td = timedelta(days=425)
else:
td = timedelta(days=424)
future = now + td
for key in self.guid:
payload = {
'app': 'icaFloorplanPage',
'sp_s': 'planName',
'sp_x_1': 'appId',
'sp_q_1': 'ica',
'sp_x_2': 'entityType',
'sp_q_2': 'unit',
'upm_field_table': '1',
'sp_x_3': 'communityIdAEM',
'sp_q_3': key,
'sp_x_4': 'floorUnitTypeCode',
'sp_q_4': self.guid[key],
# the upm.upm_startDate and upm.upm_endDate are a bit confusing.
# Their roles look swapped.
'sp_x_9': 'upm.upm_startDate',
'sp_q_max_year_9': f'{future.year:04d}',
'sp_q_max_month_9': f'{future.month:02d}',
'sp_q_max_day_9': f'{future.day:02d}',
'sp_x_10': 'upm.upm_endDate',
'sp_q_min_year_10': f'{now.year:04d}',
'sp_q_min_month_10': f'{now.month:02d}',
'sp_q_min_day_10': f'{now.day:02d}'
}
result = requests.get(self.api_floorplan_pricing_url, params=payload)
data = result.json()
total = data['total']
if total != 0:
print(f'Total: {total}')
for result in data['results']:
print(f"Apartment: {result['unitMarketingName']}")
print(f"Price: {result['unitBestPrice']}")
print(f"Floor: {result['floorLevel']}")
print(f"Date Available: {result['unitBestDate']}")
print()
def _is_leap_year(self, year):
if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0):
return True
else:
return False
def main():
print('Westview Plan P')
test = IrvineApartments(community_name='Westview', plan_name='P')
#print(test.available_apartments)
print('Los Olivos Plan J')
test = IrvineApartments(community_name='Los Olivos', plan_name='J')
#print(test.available_apartments)
print('Los Olivos Plan W')
test = IrvineApartments(community_name='Los Olivos', plan_name='W')
#print(test.available_apartments)
if __name__ == '__main__':
main()