-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathramplease.js
75 lines (61 loc) · 2.67 KB
/
ramplease.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const axios = require('axios');
const { writeFileSync, mkdirSync, existsSync } = require('fs');
const { get, set, toNumber } = require('lodash');
const cheerio = require('cheerio');
const dayjs = require('dayjs');
const kr_laptop = `http://www.enuri.com/lsv2016/ajax/getListGoods_ajax.jsp?random_seq=519
&pageNum=1&pageGap=30&tabType=0&cate=070341&keyword=&brand=&factory=
&shop_code=&prtmodelno=&gb1=&gb2=&sponsorList=&infoAdList=&IsDeliverySumPrice=N
&IsJungoPriceRemove=N&m_price=&start_price=&end_price='`;
const kr_desktop = `http://www.enuri.com/lsv2016/ajax/getListGoods_ajax.jsp?random_seq=721
&pageNum=1&pageGap=30&tabType=0&cate=070340&keyword=&brand=&factory=&shop_code=&prtmodelno=
&gb1=&gb2=&sponsorList=&infoAdList=&IsDeliverySumPrice=N&IsJungoPriceRemove=N&m_price=
&start_price=&end_price=`;
const kr = {
laptop: kr_laptop,
desktop: kr_desktop,
};
const us_laptop = `https://www.amazon.com/s?k=samsung+21300+SODIMM&rh=n%3A172500&ref=nb_sb_noss`;
const us_desktop = `https://www.amazon.com/s?k=samsung+21300+DIMM&rh=n%3A172500&ref=nb_sb_noss`;
const us = {
laptop: us_laptop,
desktop: us_desktop,
};
const capacities = [ '4G', '8G', '16G' ];
const main = async () => {
const results = {};
// Korea - enuri.com
for(const [platform, url] of Object.entries(kr)) {
const { data } = await axios.get(url);
const { groupModelList: priceList } = data.lpList.find(i => {
const model = i.strModelName;
return model.includes('삼성') && model.includes('21300');
});
for(const capacity of capacities.values()) {
const price = priceList.find(i => i.strBeginnerDicCondiname === capacity).longMinprice;
set(results, `kr.${platform}.${capacity.toLowerCase()}`, price);
}
}
// United States - amazon.com
for(const [platform, url] of Object.entries(us)) {
const { data } = await axios.get(url);
const $ = cheerio.load(data)
const list = $('.s-result-list').children();
list.each(function(index, element) {
const t = $(this).find('.a-size-medium').text().toLowerCase();
const price = $(this).find('.a-offscreen').text().slice(1);
if(!t.includes(platform)) return;
for(const capacity of capacities.map(c => c.toLowerCase()).values()) {
const path = `us.${platform}.${capacity}`;
if(!t.includes(`samsung ${capacity}`)) continue;
if(toNumber(get(results, path, Number.MAX_VALUE)) < toNumber(price)) continue;
set(results, path, price);
}
})
}
const dirname = 'data';
const filename = `${dayjs().format('YYYY-MM-DDTHH:mm:ss')}.json`;
if(!existsSync(dirname)) mkdirSync(dirname);
writeFileSync(`${dirname}/${filename}`, JSON.stringify(results))
}
main();