Spaces:
Sleeping
Sleeping
Commit ·
d5ccf1f
1
Parent(s): c2ccfc1
trying
Browse files- email_utils.py +14 -13
- index.html +0 -0
- old_files/DockerFile +0 -6
- scraper/old_scraper.py +16 -3
- scraper/scraper.py +41 -29
email_utils.py
CHANGED
|
@@ -39,23 +39,23 @@ def get_template_price_drop_email(name,product_name,product_url,previous_price,n
|
|
| 39 |
|
| 40 |
prod_name_len = 20
|
| 41 |
subject = f""" Price Drop Alert! | {product_name[:prod_name_len]+("..." if len(product_name)>prod_name_len else "")}"""
|
| 42 |
-
body = f"""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
"""
|
| 60 |
|
| 61 |
return {
|
|
@@ -68,6 +68,7 @@ def get_template_price_drop_email(name,product_name,product_url,previous_price,n
|
|
| 68 |
|
| 69 |
if __name__=="__main__":
|
| 70 |
receiver_email = os.environ["TEST_RECEIVER_EMAIL"] # Enter receiver address
|
|
|
|
| 71 |
message = """
|
| 72 |
This message is sent from Python.
|
| 73 |
"""
|
|
|
|
| 39 |
|
| 40 |
prod_name_len = 20
|
| 41 |
subject = f""" Price Drop Alert! | {product_name[:prod_name_len]+("..." if len(product_name)>prod_name_len else "")}"""
|
| 42 |
+
body = f"""
|
| 43 |
+
Hello, {name}
|
| 44 |
+
|
| 45 |
+
We are excited to inform you that the price of the product you have been monitoring has dropped!
|
| 46 |
|
| 47 |
+
Product Name: {product_name}
|
| 48 |
+
Previous Price: {previous_price}
|
| 49 |
+
New Price: {new_price}
|
| 50 |
+
Buy Product: {product_url}
|
| 51 |
+
Product Detail: https://shivam-kala-price-drop-detective.hf.space{product_detail_url}
|
| 52 |
|
| 53 |
+
Hurry up and grab this opportunity before the price changes again!
|
| 54 |
|
| 55 |
+
Thank you for using Price Drop Detective!
|
| 56 |
|
| 57 |
+
Best regards,
|
| 58 |
+
Your Price Drop Detective Team
|
| 59 |
"""
|
| 60 |
|
| 61 |
return {
|
|
|
|
| 68 |
|
| 69 |
if __name__=="__main__":
|
| 70 |
receiver_email = os.environ["TEST_RECEIVER_EMAIL"] # Enter receiver address
|
| 71 |
+
# receiver_email = os.environ["ADMIN_EMAIL"] # Enter receiver address
|
| 72 |
message = """
|
| 73 |
This message is sent from Python.
|
| 74 |
"""
|
index.html
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
old_files/DockerFile
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
# !pip install selenium # Install selenium
|
| 4 |
-
# !apt-get update # To update ubuntu to correctly run apt install
|
| 5 |
-
# !apt install chromium-chromedriver -y # Install chrome driver
|
| 6 |
-
# !cp /usr/lib/chromium-browser/chromedriver /usr/bin # Adding the driver path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scraper/old_scraper.py
CHANGED
|
@@ -30,8 +30,16 @@ data = {
|
|
| 30 |
|
| 31 |
app = Flask(__name__)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return html
|
| 36 |
|
| 37 |
|
|
@@ -50,4 +58,9 @@ def home():
|
|
| 50 |
# img = soup.find_all("img")
|
| 51 |
# print(html)
|
| 52 |
|
| 53 |
-
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
app = Flask(__name__)
|
| 32 |
|
| 33 |
+
apis = [
|
| 34 |
+
# "https://anuj-panthri-puppeteer-api.hf.space/html/",
|
| 35 |
+
"https://anuj-panthri-puppeteer-api-1.hf.space/html/",
|
| 36 |
+
"https://anuj-panthri-puppeteer-api-2.hf.space/html/",
|
| 37 |
+
"https://shivam-kala-puppeteer-api-3.hf.space/html/",
|
| 38 |
+
"https://shivam-kala-puppeteer-api-4.hf.space/html/",
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
def getData(api,url,headers={}):
|
| 42 |
+
html = requests.post(api,data={"url":url,"headers":headers}).json()["html"]
|
| 43 |
return html
|
| 44 |
|
| 45 |
|
|
|
|
| 58 |
# img = soup.find_all("img")
|
| 59 |
# print(html)
|
| 60 |
|
| 61 |
+
# app.run(debug=True)
|
| 62 |
+
|
| 63 |
+
for api in apis:
|
| 64 |
+
html=getData(api,"https://api.ipify.org/?format=json")
|
| 65 |
+
soup = BeautifulSoup(html, 'html.parser')
|
| 66 |
+
print(api,":\t",soup.find("pre").text)
|
scraper/scraper.py
CHANGED
|
@@ -5,7 +5,7 @@ from fake_useragent import UserAgent
|
|
| 5 |
from pathlib import Path
|
| 6 |
import os
|
| 7 |
from datetime import datetime
|
| 8 |
-
import requests,
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -41,7 +41,19 @@ def getDriver():
|
|
| 41 |
# if driver: driver.close()
|
| 42 |
return driver
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def getHTMLFROMAPI(url):
|
|
|
|
|
|
|
|
|
|
| 45 |
headers = {
|
| 46 |
"Accept-language": "en-GB,en;q=0.9",
|
| 47 |
"Accept-Encoding": "gzip, deflate, br",
|
|
@@ -54,8 +66,8 @@ def getHTMLFROMAPI(url):
|
|
| 54 |
"url":url,
|
| 55 |
"headers":headers,
|
| 56 |
}
|
| 57 |
-
|
| 58 |
-
res = requests.post(
|
| 59 |
return (res["html"]).encode("UTF-8")
|
| 60 |
|
| 61 |
class BaseScrapper(ABC):
|
|
@@ -224,37 +236,37 @@ if __name__ == "__main__":
|
|
| 224 |
|
| 225 |
|
| 226 |
# print(getHTMLFROMAPI(url))
|
| 227 |
-
scrapper = AmazonScrapper(driver,AmazonScrapper.getShortUrl(url))
|
| 228 |
-
print(scrapper.url)
|
| 229 |
-
data=scrapper.getData()
|
| 230 |
-
print(data)
|
| 231 |
-
# input("stop")
|
| 232 |
-
driver.close()
|
| 233 |
-
exit()
|
| 234 |
-
|
| 235 |
-
url = "https://www.amazon.com/dp/B07PVCK9KX/"
|
| 236 |
-
scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 237 |
-
print(scrapper.url)
|
| 238 |
-
print(scrapper.getData())
|
| 239 |
|
| 240 |
-
url = "https://www.amazon.com/dp/B07CNPBS7T/"
|
| 241 |
-
scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 242 |
-
print(scrapper.url)
|
| 243 |
-
print(scrapper.getData())
|
| 244 |
-
|
| 245 |
-
# url = "https://www.amazon.com/Hope-Rainbow-Hoda-Kotb/dp/0593624122/?_encoding=UTF8&_encoding=UTF8&ref_=dlx_gate_sd_dcl_tlt_fa13649f_dt_pd_gw_unk&pd_rd_w=FPLOl&content-id=amzn1.sym.81a68cec-8afc-4296-99f7-78cf5ddc15b5&pf_rd_p=81a68cec-8afc-4296-99f7-78cf5ddc15b5&pf_rd_r=KAD1QPN234SH5MXYBNW6&pd_rd_wg=A7ZKi&pd_rd_r=fa39bbc3-93b1-41a2-b592-77d89dfc6566"
|
| 246 |
-
# url = "https://www.amazon.in/Lux-Cozi-Melange-Regular-Sleeves/dp/B0CH9QMFF4/ref=sl_ob_desktop_dp_0_2_v2?_encoding=UTF8&pd_rd_w=1Bm0J&content-id=amzn1.sym.cdbcd11c-3329-43cb-9547-fb297b2c655b&pf_rd_p=cdbcd11c-3329-43cb-9547-fb297b2c655b&pf_rd_r=PTKWAM93FTVZKNGQFPVM&pd_rd_wg=iE7ky&pd_rd_r=ccfc3bd0-e267-435c-85d3-f63c78a1db0a"
|
| 247 |
-
url = "https://www.amazon.in/dp/B0CHM745CT/ref=syn_sd_onsite_desktop_0?ie=UTF8&pd_rd_plhdr=t&aref=94rDEQyVIg&th=1"
|
| 248 |
-
scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 249 |
-
print(scrapper.url)
|
| 250 |
-
print(scrapper.getData())
|
| 251 |
|
| 252 |
-
# url =
|
| 253 |
-
#
|
| 254 |
-
#
|
|
|
|
| 255 |
# print(scrapper.url)
|
| 256 |
# print(scrapper.getData())
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
# url = "https://www.flipkart.com/sti-printed-men-round-neck-white-black-t-shirt/p/itm3b20cdb30cb02"
|
| 259 |
# scrapper.updateUrl(FlipkartScrapper.getShortUrl(url))
|
| 260 |
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
import os
|
| 7 |
from datetime import datetime
|
| 8 |
+
import requests, shutil ,uuid, random
|
| 9 |
|
| 10 |
|
| 11 |
|
|
|
|
| 41 |
# if driver: driver.close()
|
| 42 |
return driver
|
| 43 |
|
| 44 |
+
|
| 45 |
+
apis = [
|
| 46 |
+
# "https://anuj-panthri-puppeteer-api.hf.space/html/",
|
| 47 |
+
"https://anuj-panthri-puppeteer-api-1.hf.space/html/",
|
| 48 |
+
"https://anuj-panthri-puppeteer-api-2.hf.space/html/",
|
| 49 |
+
"https://shivam-kala-puppeteer-api-3.hf.space/html/",
|
| 50 |
+
"https://shivam-kala-puppeteer-api-4.hf.space/html/",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
def getHTMLFROMAPI(url):
|
| 54 |
+
|
| 55 |
+
api = apis[random.randint(0,len(apis)-1)]
|
| 56 |
+
|
| 57 |
headers = {
|
| 58 |
"Accept-language": "en-GB,en;q=0.9",
|
| 59 |
"Accept-Encoding": "gzip, deflate, br",
|
|
|
|
| 66 |
"url":url,
|
| 67 |
"headers":headers,
|
| 68 |
}
|
| 69 |
+
print("using_api:",api)
|
| 70 |
+
res = requests.post(api,data=data).json()
|
| 71 |
return (res["html"]).encode("UTF-8")
|
| 72 |
|
| 73 |
class BaseScrapper(ABC):
|
|
|
|
| 236 |
|
| 237 |
|
| 238 |
# print(getHTMLFROMAPI(url))
|
| 239 |
+
# scrapper = AmazonScrapper(driver,AmazonScrapper.getShortUrl(url))
|
| 240 |
+
# print(scrapper.url)
|
| 241 |
+
# data=scrapper.getData()
|
| 242 |
+
# print(data)
|
| 243 |
+
# # input("stop")
|
| 244 |
+
# driver.close()
|
| 245 |
+
# exit()
|
| 246 |
+
|
| 247 |
+
# url = "https://www.amazon.com/dp/B07PVCK9KX/"
|
| 248 |
+
# scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 249 |
+
# print(scrapper.url)
|
| 250 |
+
# print(scrapper.getData())
|
| 251 |
|
| 252 |
+
# url = "https://www.amazon.com/dp/B07CNPBS7T/"
|
| 253 |
+
# scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 254 |
+
# print(scrapper.url)
|
| 255 |
+
# print(scrapper.getData())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
+
# # url = "https://www.amazon.com/Hope-Rainbow-Hoda-Kotb/dp/0593624122/?_encoding=UTF8&_encoding=UTF8&ref_=dlx_gate_sd_dcl_tlt_fa13649f_dt_pd_gw_unk&pd_rd_w=FPLOl&content-id=amzn1.sym.81a68cec-8afc-4296-99f7-78cf5ddc15b5&pf_rd_p=81a68cec-8afc-4296-99f7-78cf5ddc15b5&pf_rd_r=KAD1QPN234SH5MXYBNW6&pd_rd_wg=A7ZKi&pd_rd_r=fa39bbc3-93b1-41a2-b592-77d89dfc6566"
|
| 258 |
+
# # url = "https://www.amazon.in/Lux-Cozi-Melange-Regular-Sleeves/dp/B0CH9QMFF4/ref=sl_ob_desktop_dp_0_2_v2?_encoding=UTF8&pd_rd_w=1Bm0J&content-id=amzn1.sym.cdbcd11c-3329-43cb-9547-fb297b2c655b&pf_rd_p=cdbcd11c-3329-43cb-9547-fb297b2c655b&pf_rd_r=PTKWAM93FTVZKNGQFPVM&pd_rd_wg=iE7ky&pd_rd_r=ccfc3bd0-e267-435c-85d3-f63c78a1db0a"
|
| 259 |
+
# url = "https://www.amazon.in/dp/B0CHM745CT/ref=syn_sd_onsite_desktop_0?ie=UTF8&pd_rd_plhdr=t&aref=94rDEQyVIg&th=1"
|
| 260 |
+
# scrapper.updateUrl(AmazonScrapper.getShortUrl(url))
|
| 261 |
# print(scrapper.url)
|
| 262 |
# print(scrapper.getData())
|
| 263 |
|
| 264 |
+
url = 'https://www.flipkart.com/apple-iphone-15-blue-128-gb/p/itmbf14ef54f645d?pid=MOBGTAGPAQNVFZZY&lid=LSTMOBGTAGPAQNVFZZYO7HQ2L&marketplace=FLIPKART&store=tyy%2F4io&spotlightTagId=BestsellerId_tyy%2F4io&srno=b_1_1&otracker=browse&fm=organic&iid=fedd7fea-5ff7-4bd7-a5f0-a9008f1702c3.MOBGTAGPAQNVFZZY.SEARCH&ppt=browse&ppn=browse&ssid=7un6hxsq6o0000001710258321538'
|
| 265 |
+
scrapper = FlipkartScrapper(driver,FlipkartScrapper.getShortUrl(url))
|
| 266 |
+
open("index.html","wb").write(scrapper.getHTML())
|
| 267 |
+
print(scrapper.url)
|
| 268 |
+
print(scrapper.getData())
|
| 269 |
+
|
| 270 |
# url = "https://www.flipkart.com/sti-printed-men-round-neck-white-black-t-shirt/p/itm3b20cdb30cb02"
|
| 271 |
# scrapper.updateUrl(FlipkartScrapper.getShortUrl(url))
|
| 272 |
|