Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup as BS
- import matplotlib.pyplot as plt
- import requests
- import os
- import urllib.request
- URL = "http://bit.ly/2ZZKKaU"
- HEADERS = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}
- HTML_Page = requests.get(URL, headers=HEADERS)
- MySoup = BS(HTML_Page.content, "html.parser")
- def Get_Prices_Plot(Prices_Register):
- plt.plot(Prices_Register)
- plt.xlabel("Time")
- plt.ylabel("Prices")
- plt.show()
- Product_Information = (MySoup.findAll("div", {"class": "col-xs-12 col-sm-12 col-md-6"}))[1]
- Product_Name = (Product_Information.findAll("h1", {"class": "h4"}))[0].get_text()
- Product_Price = (Product_Information.findAll("div", {"class": "precioMain h1"}))[0].get_text()
- Numeric_Price = float(Product_Price.replace("€", "").replace(",", "."))
- if os.path.isfile("./Product_Prices.txt"):
- Price_File = open("./Product_Prices.txt", "r")
- FileContent = Price_File.readlines()
- Price_File.close()
- Best_Price = float(FileContent[0])
- Prices_Register = list(map(float, FileContent[1].split(",")))
- Prices_Register_List = Prices_Register
- if Best_Price > Numeric_Price:
- Best_Price = Numeric_Price
- Prices_Register.append(Numeric_Price)
- Prices_Register = str(Prices_Register).replace("[", "").replace("]", "")
- Price_File = open("./Product_Prices.txt", "w")
- Price_File.write(str(Best_Price) + str("\n"))
- Price_File.write(Prices_Register)
- Price_File.close()
- Get_Prices_Plot(Prices_Register_List)
- else:
- Price_File = open("./Product_Prices.txt", "w")
- Price_File.write(str(Numeric_Price) + str("\n"))
- Price_File.write(str(Numeric_Price))
- Price_File.close()
- Prices_Register_List = [Numeric_Price]
- Get_Prices_Plot(Prices_Register_List)
Add Comment
Please, Sign In to add comment