init push
This commit is contained in:
commit
1c424d80d1
5 changed files with 196 additions and 0 deletions
54
.gitignore
vendored
Normal file
54
.gitignore
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
25
LICENSE
Normal file
25
LICENSE
Normal file
|
@ -0,0 +1,25 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
|
12
README.md
Normal file
12
README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
leboncoin
|
||||
=========
|
||||
|
||||
Leboncoin.fr is a classifieds site, leader in France, the script leboncoin.py allows you to receive by email new ads about the object you are looking for. In the email you will get the URL link, price, photo and description of the ads.
|
||||
|
||||
- Edit leboncoin.py with your Email settings
|
||||
- Configure a cron entry with the script and put the objects you are looking for as arguments.
|
||||
For example if you want classifieds alert about lego starwars and bicycle, put in your cron: python leboncoin.py --objects "lego starwas+bicycle" > leboncoin.log 2>&1
|
||||
|
||||
Requires the non-defaults followings modules:
|
||||
- BeautifulSoup 4
|
||||
- Requests
|
0
leboncoin-db.txt
Normal file
0
leboncoin-db.txt
Normal file
105
leboncoin.py
Normal file
105
leboncoin.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
# -- coding: utf-8 --
|
||||
__author__ = "yelfathi"
|
||||
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from multiprocessing import Process
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
class Leboncoin(Process):
|
||||
URL = 'https://www.leboncoin.fr/locations/offres/aquitaine/?th=1&location=Toutes%20les%20communes%2040180&parrot=0'
|
||||
|
||||
def __init__(self):
|
||||
Process.__init__(self)
|
||||
#self.keyw = re.sub('\s+', '+', keyw)
|
||||
self.keyw = "leboncoin"
|
||||
self.url = self.URL #+ self.keyw
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
req = requests.get(self.url, timeout=5)
|
||||
except requests.ConnectionError:
|
||||
raise LookupError('Could not reach host')
|
||||
|
||||
# List of ads present on the URL page
|
||||
ad_id_list = []
|
||||
# Dict: key as LBC id of the ads, value as URL of the ads
|
||||
url_dict = {}
|
||||
# Dict: key as LBC id of the ads, value as the Title of the ads
|
||||
title_dict = {}
|
||||
|
||||
soup = BeautifulSoup(req.content, 'html.parser')
|
||||
for ad in soup.find_all('a', {'title': True}):
|
||||
ad_date = ad.find_all('div', {'class': 'date'})
|
||||
for date in ad_date:
|
||||
print date
|
||||
if date.findAll('div')[0].text == "Aujourd'hui":
|
||||
ad_url = ad['href']
|
||||
ad_id = re.findall(r'([0-9]+)\.htm', ad_url)
|
||||
ad_id_list.append(ad_id[0])
|
||||
url_dict[str(ad_id[0])] = str(ad_url)
|
||||
title_dict[str(ad_id[0])] = ad['title'].encode('utf-8')
|
||||
else:
|
||||
ad_url = ad['href']
|
||||
ad_id = re.findall(r'([0-9]+)\.htm', ad_url)
|
||||
ad_id_list.append(ad_id[0])
|
||||
url_dict[str(ad_id[0])] = str(ad_url)
|
||||
title_dict[str(ad_id[0])] = ad['title'].encode('utf-8')
|
||||
|
||||
with open(self.keyw+'-db.txt', 'a+') as my_file:
|
||||
archive = my_file.read().splitlines()
|
||||
message = ''
|
||||
for ad_id in ad_id_list:
|
||||
if ad_id not in archive:
|
||||
my_file.seek(0, 2) # For Microsoft Windows only
|
||||
my_file.write(ad_id + "\n")
|
||||
try:
|
||||
req = requests.get(url_dict.get(ad_id), timeout=5)
|
||||
except requests.ConnectionError:
|
||||
raise LookupError('Could not reach host')
|
||||
|
||||
soup = BeautifulSoup(req.content, 'html.parser')
|
||||
ad_price = soup.find('span', {'class': 'price'})
|
||||
if ad_price:
|
||||
ad_price = ad_price.text.strip()
|
||||
else:
|
||||
ad_price = 'Not specified'
|
||||
ad_image = soup.find('div', {'class': 'print-lbcImages'})
|
||||
if ad_image:
|
||||
ad_image = str(ad_image.find_all('img')[0].get('src'))
|
||||
else:
|
||||
ad_image =\
|
||||
'http://static.leboncoin.fr/img/logo_big_new.png'
|
||||
ad_description = soup.find('div', 'content')
|
||||
for tag in ad_description.findAll('br'):
|
||||
tag.extract()
|
||||
message += '<html><head></head><body><p><a href="'\
|
||||
+ url_dict.get(ad_id)\
|
||||
+ '">Link to LBC ad</a></p><p>Description: '\
|
||||
+ ad_description.text.strip()+'</p>'\
|
||||
+ '<p>Price: '+ad_price\
|
||||
+'</p><p><img alt="Main Image" src="'\
|
||||
+ ad_image\
|
||||
+ '"/></p><hr noshade width="50%" align=\
|
||||
"center"></body></html>'
|
||||
|
||||
if message:
|
||||
subject = 'Leboncoin:'
|
||||
print("https://smsapi.free-mobile.fr/sendmsg?user=11117653&pass=poUbj5QQgU9Iwm&msg=%s" % subject + message)
|
||||
requests.get("https://smsapi.free-mobile.fr/sendmsg?user=11117653&pass=poUbj5QQgU9Iwm&msg=%s" % subject + message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser(description='\
|
||||
Check on Leboncoin.fr for new ads.')
|
||||
parser.add_argument('--objects',
|
||||
help='objects to look after seperated by "+"',
|
||||
required=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
Leboncoin().start()
|
Loading…
Reference in a new issue