Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b878d9

Browse files
Amazon Wishlist Notifier
1 parent d06f742 commit 0b878d9

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

‎Amazon Wishlist Notifier/script.py‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import time
4+
import smtplib
5+
from email.mime.text import MIMEText
6+
7+
# Replace with your own email and password
8+
SENDER_EMAIL = 'your_sender_email@gmail.com'
9+
SENDER_PASSWORD = 'your_sender_password'
10+
RECIPIENT_EMAIL = 'recipient_email@example.com'
11+
12+
WISHLIST_URL = 'https://www.amazon.com/gp/registry/wishlist/YOUR_WISHLIST_ID'
13+
CHECK_INTERVAL = 3600 # Check every hour
14+
15+
def get_wishlist_items():
16+
headers = {
17+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
18+
}
19+
response = requests.get(WISHLIST_URL, headers=headers)
20+
21+
if response.status_code == 200:
22+
soup = BeautifulSoup(response.content, 'html.parser')
23+
items = soup.find_all('li', class_='a-spacing-none g-item-sortable')
24+
25+
wishlist = []
26+
for item in items:
27+
name = item.find('a', class_='a-link-normal').get_text().strip()
28+
price_element = item.find('span', class_='a-offscreen')
29+
price = price_element.get_text().strip() if price_element else "Price not available"
30+
availability = "In stock" if "In Stock" in item.get_text() else "Out of stock"
31+
wishlist.append({'name': name, 'price': price, 'availability': availability})
32+
33+
return wishlist
34+
35+
else:
36+
print("Failed to retrieve wishlist data from Amazon.")
37+
return []
38+
39+
def send_email(subject, message):
40+
msg = MIMEText(message)
41+
msg['Subject'] = subject
42+
msg['From'] = SENDER_EMAIL
43+
msg['To'] = RECIPIENT_EMAIL
44+
45+
server = smtplib.SMTP('smtp.gmail.com', 587)
46+
server.starttls()
47+
server.login(SENDER_EMAIL, SENDER_PASSWORD)
48+
server.sendmail(SENDER_EMAIL, RECIPIENT_EMAIL, msg.as_string())
49+
server.quit()
50+
51+
def main():
52+
while True:
53+
wishlist_items = get_wishlist_items()
54+
55+
for item in wishlist_items:
56+
if "Price not available" not in item['price'] and "$" in item['price']:
57+
price = float(item['price'][1:])
58+
if price < 100.00: # Set your desired price threshold
59+
subject = f"Wishlist Alert: Price drop for {item['name']}!"
60+
message = f"The price of {item['name']} has dropped to {item['price']}. Check it out on your wishlist: {WISHLIST_URL}"
61+
send_email(subject, message)
62+
elif item['availability'] == "In stock":
63+
subject = f"Wishlist Alert: {item['name']} is back in stock!"
64+
message = f"{item['name']} is now back in stock. Check it out on your wishlist: {WISHLIST_URL}"
65+
send_email(subject, message)
66+
67+
time.sleep(CHECK_INTERVAL)
68+
69+
if __name__ == "__main__":
70+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /