Skip to content

Commit d87900b

Browse files
Added Amazon price tracker (#916)
* Added Amazon price tracker * Updated Demo Video * Added Read Me file * Upated the repositry after correction * Update ReadMe.md * Removed Extra Lines * Added package files * Delete package.json Co-authored-by: vybhav72954 <[email protected]>
1 parent e4fbe01 commit d87900b

File tree

5 files changed

+407
-0
lines changed

5 files changed

+407
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Amazon Price Tracker
2+
3+
A Script to track prices of products from Amazon.
4+
5+
## Setup
6+
7+
1. Clone the folder.
8+
2. Open command line and change the directory to your folder by using ```cd foldername```.
9+
3. Run the command ```npm install```.
10+
4. Then run the script using command ```node index.js```.
11+
12+
# Output
13+
14+
![output-video] https://urlzs.com/9WgxH
15+
16+
![img] https://urlzs.com/gqyCG
17+
18+
# Author
19+
20+
[Harsh Kaushik](https://github.com/haarsh01)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const axios = require('axios');
2+
const cheerio = require('cheerio');
3+
const cron = require('node-cron');
4+
const nodemailer = require('nodemailer')
5+
const fetchPrice = async(url, targetPrice) =>{
6+
const response = await axios.get(url);
7+
const html = response.data;
8+
const $ = cheerio.load(html);
9+
const priceText = $('#priceblock_ourprice').text();
10+
const price = parseFloat(priceText.replace('$',''));
11+
if(targetPrice >= price){
12+
sendEmail(url,price);
13+
}else{
14+
console.log('too expensive');
15+
}
16+
}
17+
const sendEmail = async (url, price) => {
18+
const testAccount = await nodemailer.createTestAccount();
19+
const transport = nodemailer.createTransport({
20+
host:'smtp.ethereal.email',
21+
port: 587,
22+
secure: false,
23+
auth:{
24+
user: testAccount.user,
25+
pass:testAccount.pass,
26+
}
27+
28+
});
29+
const info = await transport.sendMail({
30+
from:'"UI Infinity" <[email protected]>',
31+
32+
subject:'amazon watcher',
33+
text:`${price} - ${url}`,
34+
html:`<p>${price}</p><p>${url}</p>`,
35+
});
36+
console.log(nodemailer.getTestMessageUrl(info));
37+
}
38+
39+
const watchPrice = (priceTaget, url, schedule = '*/5 * * * * *') => {
40+
cron.schedule(schedule, () => fetchPrice(url, priceTaget));
41+
};

JavaScript/Amazon_Price_Tracker/package-lock.json

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "amazon-price-tracker",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"axios": "^0.21.1",
13+
"cheerio": "^1.0.0-rc.6",
14+
"node-cron": "^3.0.0",
15+
"nodemailer": "^6.5.0"
16+
}
17+
}

0 commit comments

Comments
 (0)