This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_url(url): | |
if url.find("www.amazon.in") != -1: | |
index = url.find("/dp/") | |
if index != -1: | |
index2 = index + 14 | |
url = "https://www.amazon.in" + url[index:index2] | |
else: | |
index = url.find("/gp/") | |
if index != -1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_converted_price(price): | |
stripped_price = price.strip("₹ ,") | |
replaced_price = stripped_price.replace(",", "") | |
find_dot = replaced_price.find(".") | |
to_convert_price = replaced_price[0:find_dot] | |
converted_price = int(to_convert_price) | |
return converted_price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_converted_price(price): | |
# stripped_price = price.strip("₹ ,") | |
# replaced_price = stripped_price.replace(",", "") | |
# find_dot = replaced_price.find(".") | |
# to_convert_price = replaced_price[0:find_dot] | |
# converted_price = int(to_convert_price) | |
converted_price = float(re.sub(r"[^\d.]", "", price)) # Thanks to https://medium.com/@oorjahalt | |
return converted_price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_product_details(url): | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" | |
} | |
details = {"name": "", "price": 0, "deal": True, "url": ""} | |
_url = extract_url(url) | |
if _url == "": | |
details = None | |
else: | |
page = requests.get(url, headers=headers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
'asin': 'B077Q42J32', | |
'details': [ | |
{ | |
'name': 'Nokia 8.1 (Iron, 4GB RAM, 64GB Storage)', | |
'price': 19139.0, | |
'deal': False, | |
'url': 'https://www.amazon.in/dp/B077Q42J32', | |
'date': datetime.datetime(2019, 8, 7, 9, 51, 35, 648000) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_product_detail(details): | |
new = db["products"] | |
ASIN = details["url"][len(details["url"])-10:len(details["url"])] | |
details["date"] = datetime.datetime.utcnow() | |
try: | |
new.update_one( | |
{ | |
"asin":ASIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_product_history(asin): | |
new = db["products"] | |
try: | |
find = new.find_one({"asin": asin}, {"_id": 0}) | |
if find: | |
return find | |
except Exception as identifier: | |
print(identifier) | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
'asin': 'B077Q42J32', | |
'details': [ | |
{ | |
'name': 'Nokia 8.1 (Iron, 4GB RAM, 64GB Storage)', | |
'price': 19139.0, | |
'deal': False, | |
'url': 'https://www.amazon.in/dp/B077Q42J32', | |
'date': datetime.datetime(2019, 8, 7, 9, 51, 35, 648000) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db | |
import scraper | |
import time | |
URL = "https://www.amazon.in/dp/B077Q42J32/" | |
def track(): | |
details = scraper.get_product_details(URL) | |
result = "" | |
if details is None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<button class="next"> | |
<span class="icon">👉</span> | |
Next Episode Starts in | |
<span class="countdown"> | |
10 | |
<span class="numbers"> | |
<span>10</span> | |
<span>9</span> | |
<span>8</span> |
OlderNewer