Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function getPrice(today, callback){
  2. var url;
  3. var username = 'some username';
  4. var password = 'some password';
  5. url = 'some url'+ createTimeString(today);
  6.  
  7. var options = {
  8. host: 'some host',
  9. path: url,
  10. auth: username + ':' + password
  11. };
  12.  
  13. https.get(options, function(res){
  14. res.setEncoding('utf8');
  15. var body = '';
  16.  
  17. res.on('data', function(d) {
  18. body += d;
  19. var obj = JSON.parse(body);
  20. console.log(obj);
  21. callback(obj.Entries[0].EntryPx);
  22. });
  23.  
  24. res.on("end", function () {
  25. //console.log(body);
  26. });
  27.  
  28. res.on('error', function(e) {
  29. context.fail("Got error: " + e.message);
  30. });
  31. });
  32. }
  33.  
  34. getPrice(today, function(result) {
  35. curr_price = result;
  36. speechOutput = "The curr price is " + curr_price.toString();
  37.  
  38. //rest of code
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement