Skip to content

Commit

Permalink
Merge pull request #967 from AbhijitMotekar99/main
Browse files Browse the repository at this point in the history
Added Amazon product availbility checker
  • Loading branch information
UTSAVS26 authored Nov 6, 2024
2 parents 585bba9 + 096ceb0 commit f5231bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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 @@ -249,6 +249,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

0 comments on commit f5231bf

Please sign in to comment.