Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import urllib.request
  2. import gzip
  3. import re
  4. import sched, time
  5.  
  6. s = sched.scheduler(time.time, time.sleep)
  7. oldAnnonces = []
  8.  
  9. def checkAnnonces(sc):
  10. print(" Checking new annonces...")
  11. opener = urllib.request.build_opener()
  12. opener.addheaders = [('Host','www.leboncoin.fr'),
  13. ('Connection',' keep-alive'),
  14. ('Cache-Control',' max-age=0'),
  15. ('Upgrade-Insecure-Requests',' 1'),
  16. ('User-Agent',' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'),
  17. ('Accept',' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'),
  18. ('Accept-Encoding',' gzip, deflate, br'),
  19. ('Accept-Language',' fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7')
  20. ]
  21. urllib.request.install_opener(opener)
  22. response = urllib.request.urlopen("https://www.leboncoin.fr/recherche/?category=10&regions=18&cities=Nantes_44300&price=200-600&square=20-max");
  23. gzipFile = gzip.GzipFile(fileobj=response)
  24. html = gzipFile.read().decode('utf-8');
  25. newAnnonces = re.findall( r'{"list_id":([^{]*)', html, re.M|re.I)
  26. for annonce in newAnnonces:
  27. if annonce not in oldAnnonces:
  28. print("FOUND a new annonce ! \n"+annonce)
  29. oldAnnonces.append(annonce)
  30. urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=39030424&pass=nfODujINlvTlsD&msg=Nouvelle%20Annonce").read();
  31. s.enter(60, 1, checkAnnonces, (sc,))
  32.  
  33.  
  34. opener = urllib.request.build_opener()
  35. opener.addheaders = [('Host','www.leboncoin.fr'),
  36. ('Connection',' keep-alive'),
  37. ('Cache-Control',' max-age=0'),
  38. ('Upgrade-Insecure-Requests',' 1'),
  39. ('User-Agent',' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'),
  40. ('Accept',' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'),
  41. ('Accept-Encoding',' gzip, deflate, br'),
  42. ('Accept-Language',' fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7')
  43. ]
  44. urllib.request.install_opener(opener)
  45. response = urllib.request.urlopen("https://www.leboncoin.fr/recherche/?category=10&regions=18&cities=Nantes_44300&price=200-600&square=20-max");
  46. gzipFile = gzip.GzipFile(fileobj=response)
  47. html = gzipFile.read().decode('utf-8');
  48. oldAnnonces = re.findall( r'{"list_id":([^{]*)', html, re.M|re.I)
  49. urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=39030424&pass=nfODujINlvTlsD&msg=Nouvelle%20Annonce").read();
  50. print(" Added old annonces");
  51. s.enter(60, 1, checkAnnonces, (s,))
  52. s.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement