Advertisement
lounes_kmt

Untitled

Jan 26th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3. import os
  4.  
  5. url_base = 'https://www.beephone.fr/iphone-reconditionne/'
  6. cmd = '/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser '
  7.  
  8. class Product:
  9.     def __init__(self, name, colors, sizes):
  10.         self.name = name
  11.         self.colors = colors
  12.         self.sizes = sizes
  13.        
  14. def notify(title, text):
  15.     os.system("""
  16.          osascript -e 'display notification "{}" with title "{}"'
  17.          """.format(text, title))
  18.        
  19. av_delays = list()
  20.        
  21. products_objects = [Product("7", ["noir", "argent", "or", "or-rose"], ["-32-go", "-128-go"]),
  22.                     Product("7-plus", ["noir", "argent", "or", "or-rose"], ["-32-go", "-128-go", "-256-go"]),
  23.                     Product("8", ["gris-sideral", "argent", "or"], ["-64-go"]),
  24.                     Product("8-plus", ["gris-sideral", "argent", "or"], ["-64-go"]),
  25.                     Product("x", ["gris-sideral", "argent"], ["-64-go", "-256-go"]),
  26.                     Product("xr", ["noir", "blanc"], ["-64-go", "-128-go", "-256-go"])]
  27.                    
  28. prices = ['255,00 €', '268,00 €', '259,00 €', '279,00 €', '255,00 €', '278,00 €', '255,00 €', '279,00 €', '350,00 €', '375,00 €', '395,00 €', '350,00 €', '370,00 €', '395,00 €', '355,00 €', '370,00 €', '395,00 €', '350,00 €', '370,00 €', '395,00 €', '359,00 €', '355,00 €', '350,00 €', '470,00 €', '465,00 €', '470,00 €', '570,00 €', '650,00 €', '580,00 €', '660,00 €', '600,00 €', '640,00 €', '670,00 €', '610,00 €', '650,00 €']
  29.  
  30. while(1):
  31.     delays = list()
  32.     for product in products_objects:
  33.         for color in product.colors:
  34.             for size in product.sizes:
  35.                 response = requests.get(url_base + "iphone-" + product.name + "/" + color + size + "/")
  36.                 delays.append(response.elapsed.total_seconds())
  37.                 if response.status_code == 200:
  38.                     soup = BeautifulSoup(response.text, features="lxml")
  39.                     priceElmt = soup.find('h2',{'id':'gradePrice'})
  40.                     if(priceElmt):
  41.                         price = priceElmt.text
  42.                         if price != '':
  43.                             print("iPhone " + product.name + " " + color + size + " : " + price)
  44.                             if price == '1,00 €' or price == '0,99 €' or price not in prices:
  45.                                 notify("PROMO TROUVÉE", "iPhone " + product.name + " " + color + size)
  46.                                 os.system(cmd + url_base + "iphone-" + product.name + "/" + color + size + "/")
  47.     av_delay = round(sum(delays)/len(delays)*1000, 0)
  48.     print("-----Average delay : " + str(av_delay) + " ms-----")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement