Guest User

Parsing Forecast.io

a guest
Mar 23rd, 2014
887
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. httpdata = JSON.parse(global('HTTPD')); // Read in data from HTTP-get
  2. // Set up arrays to identify months and days
  3. var month = new Array();
  4. month[0] = "January";
  5. month[1] = "February";
  6. month[2] = "March";
  7. month[3] = "April";
  8. month[4] = "May";
  9. month[5] = "June";
  10. month[6] = "July";
  11. month[7] = "August";
  12. month[8] = "September";
  13. month[9] = "October";
  14. month[10] = "November";
  15. month[11] = "December";
  16.  
  17. var weekday = new Array(7);
  18. weekday[0] = "Sunday";
  19. weekday[1] = "Monday";
  20. weekday[2] = "Tuesday";
  21. weekday[3] = "Wednesday";
  22. weekday[4] = "Thursday";
  23. weekday[5] = "Friday";
  24. weekday[6] = "Saturday";
  25.  
  26. // Extract time of api request from UNIX time
  27. time = new Date(httpdata.currently.time * 1000);
  28. day = weekday[time.getDay()];
  29. months = month[time.getMonth()];
  30. date = time.getDate();
  31. if (time.getMinutes() < 10) {
  32.     clock = time.getHours() + ":0" + time.getMinutes();
  33. } else {
  34.     clock = time.getHours() + ":" + time.getMinutes();
  35. }
  36.  
  37. // Extract weather data
  38. temp = httpdata.currently.apparentTemperature; // Current temperature
  39. condition = httpdata.currently.summary; // Current weather condition summarized
  40. rain = httpdata.minutely.data[50].precipProbability * 100; // Probability of rain 50 minutes from now
  41. if (isNaN(rain)) {
  42.     rain = 0;
  43. }
  44. forecast = httpdata.hourly.summary; // Summary for the next 36 hours
  45. maxTemp = httpdata.daily.data[0].temperatureMax; // Max temperature for the day
  46.  
  47. // Extract time for sunset
  48. time = new Date(httpdata.daily.data[0].sunsetTime * 1000);
  49. if (time.getMinutes() < 10) {
  50.     sunset = time.getHours() + ":0" + time.getMinutes();
  51. } else {
  52.     sunset = time.getHours() + ":" + time.getMinutes();
  53. }
  54.  
  55. // Setup string for text to speech
  56. string = "Good morning. The time is " + clock + " on " + day + " " + months + " " + date + ". The current temperature is " + temp + " degrees Celsius and it is currently " + condition + " outside. There is a " + rain + " percent chance that it will rain in the next hour. The forecast for the day is " + forecast + ", with a maximum temperature of " + maxTemp + " degrees Celsius. Sunset is at " + sunset + " today.";
  57. //flashLong(string);
  58. setGlobal('READOUT', string); // Write string to Tasker variable
  59. exit();
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×