-
Notifications
You must be signed in to change notification settings - Fork 0
/
zonaprop.py
76 lines (54 loc) · 1.98 KB
/
zonaprop.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
"""Lookup for houses at inmoclick.com.ar."""
# import re
import json
import mailgun
import common
from bs4 import BeautifulSoup
def fetch(url):
"""Fetch pick ups."""
# Get a file-like object using urllib2.urlopen
base_url = 'https://www.zonaprop.com.ar/'
filter = url
html = common.fetch_html(base_url + filter)
soup = BeautifulSoup(html, features="html.parser")
houses = []
for card_item in soup.select('div[class*="posting-card"]'):
data = {}
link_item = card_item['data-to-posting']
data['link'] = base_url + link_item[1:]
data['id'] = card_item['data-id']
description = card_item.select_one(
'div[class*="posting-description"]'
)
data['description'] = description.get_text()
price_item = card_item.select_one('span[class*="first-price"] b')
data['price'] = price_item.get_text()
houses.append(data)
return houses
def main():
"""App controller."""
provider = 'zonaprop'
urls = [
'casas-alquiler-maipu-con-pileta-menos-140000-pesos.html',
'casas-alquiler-lujan-de-cuyo-con-pileta-menos-140000-pesos.html',
'casas-alquiler-godoy-cruz-con-pileta-menos-140000-pesos.html',
'casas-alquiler-chacras-de-coria-con-pileta-menos-140000-pesos.html',
'casas-alquiler-carrodilla-con-pileta-menos-140000-pesos.html',
]
houses_candidates = []
for url in urls:
candidates = fetch(url)
houses_candidates = houses_candidates + candidates
known_ids = common.get_known_ids(provider)
houses = common.clean_candidates_id_list(houses_candidates, known_ids)
print(houses)
print(known_ids)
# if new houses...
if len(houses):
email_subject = "Nuevas casas Zonaprop"
email_body = json.dumps(houses)
mailgun.send_simple_message(email_subject, email_body)
for house in houses:
common.add_new_id(house['id'], provider)
if __name__ == '__main__':
main()