-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
406 lines (353 loc) · 12.8 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
"use strict";
const resp = `<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="isokur.xsl"?>
<Tarih_Date Tarih="31.03.2023" Date="03/31/2023" Bulten_No="2023/65" >
<Currency CrossOrder="0" Kod="USD" CurrencyCode="USD">
<Unit>1</Unit>
<Isim>ABD DOLARI</Isim>
<CurrencyName>US DOLLAR</CurrencyName>
<ForexBuying>19.1532</ForexBuying>
<ForexSelling>19.1878</ForexSelling>
<BanknoteBuying>19.1398</BanknoteBuying>
<BanknoteSelling>19.2165</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="1" Kod="AUD" CurrencyCode="AUD">
<Unit>1</Unit>
<Isim>AVUSTRALYA DOLARI</Isim>
<CurrencyName>AUSTRALIAN DOLLAR</CurrencyName>
<ForexBuying>12.7845</ForexBuying>
<ForexSelling>12.8679</ForexSelling>
<BanknoteBuying>12.7257</BanknoteBuying>
<BanknoteSelling>12.9451</BanknoteSelling>
<CrossRateUSD>1.4946</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="2" Kod="DKK" CurrencyCode="DKK">
<Unit>1</Unit>
<Isim>DANİMARKA KRONU</Isim>
<CurrencyName>DANISH KRONE</CurrencyName>
<ForexBuying>2.7941</ForexBuying>
<ForexSelling>2.8079</ForexSelling>
<BanknoteBuying>2.7922</BanknoteBuying>
<BanknoteSelling>2.8143</BanknoteSelling>
<CrossRateUSD>6.8441</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="9" Kod="EUR" CurrencyCode="EUR">
<Unit>1</Unit>
<Isim>EURO</Isim>
<CurrencyName>EURO</CurrencyName>
<ForexBuying>20.8450</ForexBuying>
<ForexSelling>20.8825</ForexSelling>
<BanknoteBuying>20.8304</BanknoteBuying>
<BanknoteSelling>20.9138</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther>1.0883</CrossRateOther>
</Currency>
<Currency CrossOrder="10" Kod="GBP" CurrencyCode="GBP">
<Unit>1</Unit>
<Isim>İNGİLİZ STERLİNİ</Isim>
<CurrencyName>POUND STERLING</CurrencyName>
<ForexBuying>23.6602</ForexBuying>
<ForexSelling>23.7836</ForexSelling>
<BanknoteBuying>23.6437</BanknoteBuying>
<BanknoteSelling>23.8192</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther>1.2374</CrossRateOther>
</Currency>
<Currency CrossOrder="3" Kod="CHF" CurrencyCode="CHF">
<Unit>1</Unit>
<Isim>İSVİÇRE FRANGI</Isim>
<CurrencyName>SWISS FRANK</CurrencyName>
<ForexBuying>20.8615</ForexBuying>
<ForexSelling>20.9955</ForexSelling>
<BanknoteBuying>20.8302</BanknoteBuying>
<BanknoteSelling>21.0270</BanknoteSelling>
<CrossRateUSD>0.9160</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="4" Kod="SEK" CurrencyCode="SEK">
<Unit>1</Unit>
<Isim>İSVEÇ KRONU</Isim>
<CurrencyName>SWEDISH KRONA</CurrencyName>
<ForexBuying>1.8413</ForexBuying>
<ForexSelling>1.8604</ForexSelling>
<BanknoteBuying>1.8400</BanknoteBuying>
<BanknoteSelling>1.8647</BanknoteSelling>
<CrossRateUSD>10.36</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="6" Kod="CAD" CurrencyCode="CAD">
<Unit>1</Unit>
<Isim>KANADA DOLARI</Isim>
<CurrencyName>CANADIAN DOLLAR</CurrencyName>
<ForexBuying>14.1179</ForexBuying>
<ForexSelling>14.1815</ForexSelling>
<BanknoteBuying>14.0656</BanknoteBuying>
<BanknoteSelling>14.2354</BanknoteSelling>
<CrossRateUSD>1.3548</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="11" Kod="KWD" CurrencyCode="KWD">
<Unit>1</Unit>
<Isim>KUVEYT DİNARI</Isim>
<CurrencyName>KUWAITI DINAR</CurrencyName>
<ForexBuying>62.0809</ForexBuying>
<ForexSelling>62.8932</ForexSelling>
<BanknoteBuying>61.1496</BanknoteBuying>
<BanknoteSelling>63.8366</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther>3.2595</CrossRateOther>
</Currency>
<Currency CrossOrder="7" Kod="NOK" CurrencyCode="NOK">
<Unit>1</Unit>
<Isim>NORVEÇ KRONU</Isim>
<CurrencyName>NORWEGIAN KRONE</CurrencyName>
<ForexBuying>1.8317</ForexBuying>
<ForexSelling>1.8440</ForexSelling>
<BanknoteBuying>1.8304</BanknoteBuying>
<BanknoteSelling>1.8483</BanknoteSelling>
<CrossRateUSD>10.43</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="8" Kod="SAR" CurrencyCode="SAR">
<Unit>1</Unit>
<Isim>SUUDİ ARABİSTAN RİYALİ</Isim>
<CurrencyName>SAUDI RIYAL</CurrencyName>
<ForexBuying>5.1025</ForexBuying>
<ForexSelling>5.1117</ForexSelling>
<BanknoteBuying>5.0642</BanknoteBuying>
<BanknoteSelling>5.1500</BanknoteSelling>
<CrossRateUSD>3.7537</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="5" Kod="JPY" CurrencyCode="JPY">
<Unit>100</Unit>
<Isim>JAPON YENİ</Isim>
<CurrencyName>JAPENESE YEN</CurrencyName>
<ForexBuying>14.3356</ForexBuying>
<ForexSelling>14.4306</ForexSelling>
<BanknoteBuying>14.2826</BanknoteBuying>
<BanknoteSelling>14.4854</BanknoteSelling>
<CrossRateUSD>133.29</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="12" Kod="BGN" CurrencyCode="BGN">
<Unit>1</Unit>
<Isim>BULGAR LEVASI</Isim>
<CurrencyName>BULGARIAN LEV</CurrencyName>
<ForexBuying>10.5976</ForexBuying>
<ForexSelling>10.7363</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>1.7972</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="13" Kod="RON" CurrencyCode="RON">
<Unit>1</Unit>
<Isim>RUMEN LEYİ</Isim>
<CurrencyName>NEW LEU</CurrencyName>
<ForexBuying>4.1875</ForexBuying>
<ForexSelling>4.2423</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>4.5483</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="14" Kod="RUB" CurrencyCode="RUB">
<Unit>1</Unit>
<Isim>RUS RUBLESİ</Isim>
<CurrencyName>RUSSIAN ROUBLE</CurrencyName>
<ForexBuying>0.24650</ForexBuying>
<ForexSelling>0.24972</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>77.27</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="15" Kod="IRR" CurrencyCode="IRR">
<Unit>100</Unit>
<Isim>İRAN RİYALİ</Isim>
<CurrencyName>IRANIAN RIAL</CurrencyName>
<ForexBuying>0.04535</ForexBuying>
<ForexSelling>0.04594</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>42000</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="16" Kod="CNY" CurrencyCode="CNY">
<Unit>1</Unit>
<Isim>ÇİN YUANI</Isim>
<CurrencyName>CHINESE RENMINBI</CurrencyName>
<ForexBuying>2.7716</ForexBuying>
<ForexSelling>2.8079</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>6.8718</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="17" Kod="PKR" CurrencyCode="PKR">
<Unit>1</Unit>
<Isim>PAKİSTAN RUPİSİ</Isim>
<CurrencyName>PAKISTANI RUPEE</CurrencyName>
<ForexBuying>0.06714</ForexBuying>
<ForexSelling>0.06802</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>283.65</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="18" Kod="QAR" CurrencyCode="QAR">
<Unit>1</Unit>
<Isim>KATAR RİYALİ</Isim>
<CurrencyName>QATARI RIAL</CurrencyName>
<ForexBuying>5.2039</ForexBuying>
<ForexSelling>5.2719</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>3.6600</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="19" Kod="KRW" CurrencyCode="KRW">
<Unit>1</Unit>
<Isim>GÜNEY KORE WONU</Isim>
<CurrencyName>SOUTH KOREAN WON</CurrencyName>
<ForexBuying>0.01460</ForexBuying>
<ForexSelling>0.01479</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>1304</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="20" Kod="AZN" CurrencyCode="AZN">
<Unit>1</Unit>
<Isim>AZERBAYCAN YENİ MANATI</Isim>
<CurrencyName>AZERBAIJANI NEW MANAT</CurrencyName>
<ForexBuying>11.2035</ForexBuying>
<ForexSelling>11.3501</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>1.7000</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="21" Kod="AED" CurrencyCode="AED">
<Unit>1</Unit>
<Isim>BİRLEŞİK ARAP EMİRLİKLERİ DİRHEMİ</Isim>
<CurrencyName>UNITED ARAB EMIRATES DIRHAM</CurrencyName>
<ForexBuying>5.1859</ForexBuying>
<ForexSelling>5.2537</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>3.6727</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="0" Kod="XDR" CurrencyCode="XDR">
<Unit>1</Unit>
<Isim>ÖZEL ÇEKME HAKKI (SDR) </Isim>
<CurrencyName>SPECIAL DRAWING RIGHT (SDR) </CurrencyName>
<ForexBuying>25.8016</ForexBuying>
<ForexSelling/>
<BanknoteBuying/>
<BanknoteSelling/>
<CrossRateUSD/>
<CrossRateOther>1.34590</CrossRateOther>
</Currency>
</Tarih_Date>`
const parser = new DOMParser();
const xml = parser.parseFromString(resp, "application/xml");
console.log(xml, xml.nodeType)
let exchangeRates = {}
let obj = _convertXmlToJson(xml)
let tarih_date = xml.getElementsByTagName("Tarih_Date")
if (tarih_date.length > 0) {
for (let index = 0; index < tarih_date.length; index++) {
// collect attr
if (tarih_date[index].hasAttributes()) {
exchangeRates["meta"] = {}
for (let j = 0; j < tarih_date[index].attributes.length; j++) {
let attribute = tarih_date[index].attributes.item(j)
exchangeRates["meta"][attribute.nodeName.toLowerCase()] = attribute.nodeValue
}
}
// collect child nodes
let currency = tarih_date[index].getElementsByTagName("Currency")
if (currency.length > 0) {
exchangeRates["currency"] = {}
for(let i = 0; i < currency.length; i++) {
let currentCurrency = null
let currentCurrencyMeta = {}
let item = currency.item(i)
//exchangeRates["currency"][i] = {}
//exchangeRates["currency"][i]["meta"] = {}
// collect attr
if (item.hasAttributes()) {
for (let j = 0; j < item.attributes.length; j++) {
let attribute = item.attributes.item(j)
if (attribute.nodeName.toLowerCase() === "currencycode") {
currentCurrency = attribute.nodeValue
exchangeRates["currency"][currentCurrency] = {}
//exchangeRates["currency"][currentCurrency]["meta"] = {}
}
currentCurrencyMeta[attribute.nodeName.toLowerCase()] = attribute.nodeValue
}
}
//exchangeRates["currency"][currentCurrency]["meta"] = currentCurrencyMeta
exchangeRates["currency"][currentCurrency] = Object.assign({}, currentCurrencyMeta)
if (item.hasChildNodes()) {
for(let k = 0; k < item.childNodes.length; k++) {
let citem = item.childNodes.item(k)
if (citem.hasChildNodes()) {
exchangeRates["currency"][currentCurrency][citem.nodeName.toLowerCase()] = citem.childNodes[0].nodeValue
}
//console.log("NEE", citem.nodeName, citem)
}
}
//console.log("item", item)
}
}
//console.log("tarih_date",index, currency.length)
}
}
console.log("exchangeRates", exchangeRates)
console.log(exchangeRates, obj)
function _convertXmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
// do attributes
if (xml.attributes.length > 0) {
obj["attributes"] = {};
for (var j = 0; j < xml.attributes.length; j++) {
var attribute = xml.attributes.item(j);
obj["attributes"][attribute.nodeName] = attribute.nodeValue;
}
}
} else if (xml.nodeType == 3) { // text
let val = (xml.nodeValue).trim()
if (!!val) {
obj = val;
}
}
// do children
if (xml.hasChildNodes()) {
for(var i = 0; i < xml.childNodes.length; i++) {
var item = xml.childNodes.item(i);
var nodeName = item.nodeName;
nodeName = nodeName.replace(/^#/, '')
if (typeof(obj[nodeName]) == "undefined") {
obj[nodeName] = _convertXmlToJson(item);
} else {
if (typeof(obj[nodeName].push) == "undefined") {
var old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(_convertXmlToJson(item));
}
}
}
return obj;
}