Skip to content

Instantly share code, notes, and snippets.

@bee-san
Created December 20, 2015 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bee-san/32bbe4d1f4af30555ae3 to your computer and use it in GitHub Desktop.
Save bee-san/32bbe4d1f4af30555ae3 to your computer and use it in GitHub Desktop.
Checks Amazon to see if the price of a product has changed, if it's gone lower it'll email you, if not it won't do anything.
import bs4
import requests
def main():
file = open("amazon.txt", 'r')
for i in file:
print(i)
amazon_product = i
amazon_product = amazon_product.split(" ")
print(amazon_product)
amazon_price = amazon_product[0]
print(amazon_price)
amazon_new = GetAmazonPrice(amazon_product[1])
if amazon_price > amazon_new:
amazon_product[0] = amazon_price
print("The price is cheaper!")
lines = file.readlines()
lines[i] = amazon_new
file.close()
file.open("amazon.txt", 'w')
file.write(lines)
file.close()
else:
print("Price has not changed")
# send email
def GetAmazonPrice(productURL):
res = requests.get((productURL))
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
elems = (soup.select(""".a-text-normal"""))
price = (elems[0].text.strip())
return price
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment