Created
February 20, 2017 09:24
-
-
Save jokull/f8ba11a372db7eacfa0be06d0dad7a15 to your computer and use it in GitHub Desktop.
Get notified when a new property listing on visir.is is discovered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import lxml.html | |
from lxml.cssselect import CSSSelector | |
import requests | |
cookies = { | |
'session_name': 'dpoiudav0gnu6e8uf2uklift63', | |
} | |
headers = { | |
'Accept-Encoding': 'gzip, deflate, sdch', | |
'Accept-Language': 'en-US,en;q=0.8', | |
'Accept': '*/*', | |
'Referer': 'http://fasteignir.visir.is/search/results/?stype=sale', | |
'X-Requested-With': 'XMLHttpRequest', | |
'Connection': 'keep-alive', | |
} | |
response = requests.get( | |
'http://fasteignir.visir.is/ajaxsearch/' | |
'getresults?zip=101,103,104,105,107,108,109&price=32000000,45000000&' | |
'room=3,4×pan=7&stype=sale&viewmode=list', | |
headers=headers, cookies=cookies | |
) | |
tree = lxml.html.fromstring(response.text) | |
sel = CSSSelector('div.b-products-item-details h2 a') | |
scanned_path = os.path.join(os.path.dirname(__file__), '.scanned') | |
with open(scanned_path, 'r') as fp: | |
scanned = [l for l in fp.read().splitlines() if l] | |
with open(scanned_path, 'a') as fp: | |
for result in sel(tree): | |
title = result.text.strip() | |
link = 'http://fasteignir.visir.is' + result.get('href').split('?')[0] | |
if link in scanned: | |
continue | |
fp.write(link + '\n') | |
requests.post( | |
'https://api.pushbullet.com/v2/pushes', | |
data=json.dumps(dict(type='link', title=title, url=link)), | |
headers={ | |
'access-token': os.enviro['PUSHBULLET_TOKEN'], | |
'content-type': 'application/json' | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment