Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Amazon product availbility checker #967

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Beginner_Projects/Amazon product availbility checker/amazon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests
from bs4 import BeautifulSoup


def check_amazon_availability(product_url):
headers = {
"User-Agent": "Your User Agent Here" # Replace with a valid user agent string
}

try:
response = requests.get(product_url, headers=headers)
response.raise_for_status()

soup = BeautifulSoup(response.content, "html.parser")

title = soup.find("span", {"id": "productTitle"}).get_text(strip=True)
availability = soup.find(
"span", {"class": "a-declarative", "data-asin": True}
).get_text(strip=True)

if "out of stock" in availability.lower():
print(f"{title} is currently out of stock on Amazon.")
else:
print(f"{title} is available on Amazon.")

except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except requests.exceptions.RequestException as req_err:
print(f"Request error occurred: {req_err}")


if __name__ == "__main__":
product_url = "YOUR_PRODUCT_URL_HERE"
check_amazon_availability(product_url)
2 changes: 2 additions & 0 deletions Project-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
* [Models](Automation_Tools/api_dev/models.py)

## Beginner Projects
* Amazon Product Availbility Checker
* [Amazon](Beginner_Projects/Amazon%20product%20availbility%20checker/amazon.py)
* Anime Manga Tracker
* [Anime Manga Tracker](Beginner_Projects/Anime_Manga_Tracker/Anime_Manga_Tracker.py)
* Bmi Calculator
Expand Down
Loading