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,OAAS,EACd,QAAQ,IAAI,GACZ,EAAI,KAAK,EACb,IAGZ,IAEA,IAAI,OAAO,KAAM,WACf,QAAQ,IAAI,0BACd","file":"/npm/google-finance-api@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/google-finance-api@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var express = require('express')\r\nvar app = express()\r\n\r\napp.get('/', function (req, res) {\r\n    var json = {'result':'error','currency':'0','amount':'0','reason':''}\r\n\r\n    var from\r\n    var to\r\n    var amount\r\n\r\n    from = req.query['from']\r\n    to = req.query['to']\r\n    amount = req.query['amount']\r\n\r\n    if(from === 'undefined' || to === 'undefined' || amount === 'undefined') {\r\n        json.result = 'error'\r\n        console.log(json)\r\n        res.send(json)\r\n    } else {\r\n        if(from === '' || to === '' || amount === '') {\r\n            json.reason = 'parameter was empty'\r\n            res.send(json)\r\n        } else {\r\n            console.log('from: ' + from)\r\n            console.log('to: ' + to)\r\n            console.log('amount: ' + amount)\r\n\r\n            convert(amount, from, to, function(result) {\r\n                if(result === 'undefined') {\r\n                    json.result = 'error'\r\n                    console.log(json)\r\n                    res.send(json)\r\n                } else {\r\n                    json.result = 'success'\r\n                }\r\n                json.currency = to\r\n                json.amount = result\r\n                console.log(json)\r\n                res.send(json)\r\n            })\r\n        }\r\n    }\r\n})\r\n\r\napp.listen(3000, function () {\r\n  console.log('Listening on port 3000.')\r\n})\r\n\r\nfunction convert(amount, from, to, callback) {\r\n    var http = require('http')\r\n    var options = {\r\n        host: 'www.google.com',\r\n        path: '/finance/converter?a={amount}&from={from}&to={to}'.replace('{amount}',amount).replace('{from}',from).replace('{to}',to)\r\n    }\r\n\r\n    var req = http.get(options, function(res) {\r\n        var bodyChunks = []\r\n        res.on('data', function(chunk) {\r\n            bodyChunks.push(chunk)\r\n        }).on('end', function() {\r\n            var body = Buffer.concat(bodyChunks) + ''\r\n            var html = body.substring(body.lastIndexOf(\"<span class=bld>\")+1,body.lastIndexOf(\"<input type=submit value=\\\"Convert\\\">\"))\r\n            var myRegexp = /[0-9]+\\.[0-9]+/\r\n            var match = myRegexp.exec(html)\r\n            callback(match[0])\r\n        })\r\n    })\r\n\r\n    req.on('error', function(e) {\r\n        console.log('ERROR: ' + e.message)\r\n    })\r\n}\r\n"]}