Last active
August 29, 2015 13:56
-
-
Save rittme/9228213 to your computer and use it in GitHub Desktop.
seloger auto search for new housing
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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from urllib import urlencode | |
import urllib2 | |
import json | |
import smtplib | |
from pprint import pprint | |
FILE_NAME = "selogerRefs.json" | |
MAX_PAGES = 5 | |
try: | |
with open(FILE_NAME, 'r') as f: | |
refs = json.load(f) | |
except IOError: | |
refs = {} | |
newRefs = {} | |
alist = [] | |
url= 'http://www.seloger.com/new_recherche,js,liste_resultat.json?idtt=1&idtypebien=1&idtypebien=2&&ci=690386%2C690266&pxmax=750&surfacemin=40&&si_boxes=1&tri=d_dt_crea&&ANNONCEpg=' | |
for i in range(1,MAX_PAGES): | |
content =urllib2.urlopen(url+str(i)).read() | |
parsed = json.loads(content) | |
for annonce in parsed["annonces"]: | |
if (not refs.has_key(annonce["idannonce"])): | |
annonceTupple = (annonce["cp"], annonce["prix"], annonce["criteres"], annonce["description_small"], annonce["urlvirtuelle"]) | |
s = '\n%s - %s - %s\n%s\n%s' % annonceTupple | |
alist.append(s) | |
refs[annonce["idannonce"]] = annonce["urlvirtuelle"] | |
if(len(alist) > 0): | |
with open(FILE_NAME,'w') as f: | |
f.write(json.dumps(refs)) | |
text = '\n'.join(alist) | |
fromaddr = 'user@gmail.com' | |
toaddrs = 'user@gmail.com' | |
subject = '%i nouveaux apparts seloger' % len(alist) | |
msg = u'Subject: %s\n\nNouveaux annonces: \n%s' % (subject, text) | |
# Credentials (if needed) | |
username = 'user' | |
password = 'password' | |
# The actual mail send | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.starttls() | |
server.login(username,password) | |
server.sendmail(fromaddr, toaddrs, msg.encode('utf-8')) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment