-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
226 lines (186 loc) · 8.61 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
var currencyUrl = "https://www.tgju.org/currency";
var footbalTableUrl = "https://www.varzesh3.com/";
const cheerio = require('cheerio');
const got = require('got');
const fetchAll = async function () {
var response = await got(currencyUrl);
var $ = cheerio.load(response.body);
// currency
var dollar = {
price : $('#l-price_dollar_rl > span > span.info-price').text(),
change : _findPriceChange($('#l-price_dollar_rl > span > span.info-change'),$),
codes : "USD",
symbol : "$"
};
var euro = {
price : $('#l-price_eur > span > span.info-price').text(),
change : _findPriceChange($('#l-price_eur > span > span.info-change'),$),
codes : "EUR",
symbol : "€"
};
var bitcoin = {
price : $('#l-crypto-bitcoin > span > span.info-price').text(),
change : _findPriceChange($('#l-crypto-bitcoin > span > span.info-change'),$),
codes : "BTC",
symbol : "₿"
};
var pound = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(3) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(3) > td:nth-child(3)'),$),
codes : "GBP",
symbol : "£"
};
var uae = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(3)'),$),
codes : "AED",
symbol : "د.إ"
};
var lier = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(5) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(5) > td:nth-child(3)'),$),
codes : "TRY",
symbol : "₺"
};
var franc = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(6) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(6) > td:nth-child(3)'),$),
codes : "CHF",
symbol : "fr"
};
var yuan = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(7) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(7) > td:nth-child(3)'),$),
codes : "CNY",
symbol : "¥"
};
var canadaDollar = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(10) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(10) > td:nth-child(3)'),$),
codes : "CAD",
symbol : "$"
};
var austDollar = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(11) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(11) > td:nth-child(3)'),$),
codes : "AUD",
symbol : "$"
}
var iraqDinar = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(16) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(1) > table > tbody > tr:nth-child(16) > td:nth-child(3)'),$),
codes : "IQD",
symbol : "د.ع"
}
var sweedSek = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(3)'),$),
codes : "SEK",
symbol : "kr"
}
var saudiArabiaRials = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(4) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(4) > td:nth-child(3)'),$),
codes : "SAR",
symbol : "﷼"
}
var qatarRials = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(5) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(5) > td:nth-child(3)'),$),
codes : "QAR",
symbol : "﷼"
}
var omanRials = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(6) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(6) > td:nth-child(3)'),$),
codes : "OMR",
symbol : "﷼"
}
var roble = {
price : $('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(12) > td:nth-child(2)').html(),
change : _findPriceChange($('#main > div:nth-child(6) > div > div > div:nth-child(2) > table > tbody > tr:nth-child(12) > td:nth-child(3)'),$),
codes : "RUB",
symbol : "₽"
}
//-- gold
var seke = $('#l-sekee > span > span.info-price').text();
var goldOns = $('#l-ons > span > span.info-price').text();
var goldMesghal = $('#l-mesghal > span > span.info-price').text();
var gold18 = $('#l-geram18 > span > span.info-price').text();
var oilBrent = $('#l-oil_brent > span > span.info-price').text();
var iranstock = $('#l-bourse > span > span.info-price').text();
var createtime = (new Date().getTime());
var output = {
"timestamp": createtime,
"currency": {
dollar,
euro,
bitcoin,
pound,
canadaDollar,
austDollar,
franc,
sweedSek,
lier,
yuan,
roble,
uae,
iraqDinar,
saudiArabiaRials,
qatarRials,
omanRials,
},
"gold": {
seke,
goldOns,
goldMesghal,
gold18
},
"oil": { oilBrent },
"other": { iranstock, bitcoin },
}
return output;
};
const fetchFootbalLeageTable = async function()
{
var table = [];
var response2 = await got(footbalTableUrl);
var $2 = cheerio.load(response2.body);
$2('div.widget-body > div.widget-table > div.table-holder > table.league-standing tr').each((i, item) => {
var text1 = $2('td:nth-child(1)', item).text();
var text2 = $2('td:nth-child(2)', item).text();
var text3 = $2('td:nth-child(3)', item).text();
var text4 = $2('td:nth-child(4)', item).text();
if(text1)
table.push({ rank: text1,team: text2.trim(), point: text4.trim(), match: text3 });
})
return table;
}
const _findPriceChange = function(elm,$){
let firstLevelClass = elm.attr('class');
let firstchild = elm.children().get(0);
let targetClassName = null;
/* --- find target element that containt class name tell us is change highe or low --- */
if (firstchild && firstchild.tagName == 'span') // if target item is in the main page
targetClassName = $(firstchild).attr('class');
else // if target item is main sticky bar
{
let parent = elm.parents('li');
targetClassName = parent.attr('class');
}
if (targetClassName.indexOf('high') > -1)
return {
type : "positive" ,
change : elm.text()
};
if (firstLevelClass.indexOf('low') > -1)
return {
type : "negative",
change : elm.text()
};
return {
type: "none",
change: elm.text()
};
}
module.exports = {fetchAll, fetchFootbalLeageTable};