-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (65 loc) · 2.25 KB
/
main.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
from parser import Parser, Parser_Zonaprops
import smtplib
import requests
import os
from dotenv import load_dotenv
import json
def filter_data():
# filters = []
with open('data.json') as file:
data = json.load(file)
lower_price = 9999999999
selected_prop = {
'url': '',
'price': 0,
}
for prop in data:
current_price = int(data[prop]['price'].replace('.', ''))
if data[prop]['coin'] == 'U$S':
# convert dolar price in to argentinians pesos
# We should have an env var for conversion
current_price = current_price * 160
if current_price < lower_price:
selected_prop['url'] = data[prop]['url']
selected_prop['price'] = current_price
lower_price = current_price
print(lower_price)
return selected_prop
def send_notification(telegram_id=None, content=''):
if telegram_id:
print(f'Sending telegram notification to {telegram_id}')
load_dotenv()
telegram_token = os.getenv("TELEGRAM_TOKEN")
dest = f'https://api.telegram.org/bot{telegram_token}/sendMessage'
data = {
'chat_id': telegram_id,
'text': content,
}
req = requests.post(dest, data)
if req.ok:
print("SUCCESS")
return True
else:
print(req.text)
return False
def main():
selected_prop = filter_data()
quarter = "TEST_ZONE"
price = selected_prop['price']
link = selected_prop['url']
data = f"I've found a nice place for you in {quarter}. Price ${price}. "\
f"Follow the link for more information {link}"
# send_notification('1090248198', content=data)
send_notification('-593008804', content=data)
return 0
# uncomment for test with the interactive shell ( python -i main.py ):
meliprops = Parser(
web='mercado_libre',
website='https://inmuebles.mercadolibre.com.ar/departamentos/alquiler/capital-federal', # noqa
page_limit=0,
)
argenprop = Parser(
web='argen_prop',
website='https://www.argenprop.com/departamento-alquiler-localidad-capital-federal', # noqa
page_limit=2,
)