Advertisement
elythomaslumber

tweet-wunderground.php

Feb 10th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. //---get forecast for the next hours-------------------------
  5. //---see the wunderground webpage for other weather information download
  6. //---uselang:xx for language of your country
  7. //---change hourly to other values for other weather information
  8. //---change country and city
  9. $json_string = file_get_contents("http://api.wunderground.com/api/xxxxxxxxxxxxxxxx/hourly/lang:DL/q/germany/Solingen.json");
  10. $parsed_json = json_decode($json_string, true);
  11.  
  12.  
  13. //---for debugging and development of own forecast combination
  14. //---this file will show the complete array of a weather forecast
  15. /**
  16. $wetterdatei = "/home/pi/domoticz/scripts/wetter_json.txt";
  17. $wd = fopen ($wetterdatei, "w+");
  18. fwrite ($wd, print_R($parsed_json, TRUE));
  19. fclose ($wd);
  20. */
  21.  
  22. //--------- Wetter in 2h ------------------------------------
  23. //---look at the wetter_json.txt file about the structure
  24. $parsed_json = $parsed_json['hourly_forecast'][1]['FCTTIME'];
  25. //print_r($parsed_json);
  26.  
  27. $stunde = $parsed_json['hour_padded'];
  28. $min = $parsed_json['min'];
  29. $tag = $parsed_json['mday_padded'];
  30. $monat = $parsed_json['mon_abbrev'];
  31. $jahr = $parsed_json['year'];
  32. echo $stunde.":".$min." ".$tag.".".$monat.".".$jahr."\n";
  33.  
  34. $parsed_json = json_decode($json_string, true);
  35. $parsed_json = $parsed_json['hourly_forecast'][1]['temp'];
  36. $temp = $parsed_json['metric'];
  37. echo "Temp ".$temp."C"."\n";
  38.  
  39. $parsed_json = json_decode($json_string, true);
  40. $parsed_json = $parsed_json['hourly_forecast'][1]['wspd'];
  41. $windspeed = $parsed_json['metric'];
  42. echo "Wind ".$windspeed."km/h"."\n";
  43.  
  44. $parsed_json = json_decode($json_string, true);
  45. $parsed_json = $parsed_json['hourly_forecast'][1]['wdir'];
  46. $winddir = $parsed_json['dir'];
  47. echo "Windricht. ".$winddir."\n";
  48.  
  49. $parsed_json = json_decode($json_string, true);
  50. $parsed_json = $parsed_json['hourly_forecast'][1];
  51. $humy = $parsed_json['humidity'];
  52. echo "Luftf. ".$humy."%"."\n";
  53.  
  54. $parsed_json = json_decode($json_string, true);
  55. $parsed_json = $parsed_json['hourly_forecast'][1]['qpf'];
  56. $regen = $parsed_json['metric'];
  57. echo "Regen ".$regen."mm"."\n";
  58.  
  59. $parsed_json = json_decode($json_string, true);
  60. $parsed_json = $parsed_json['hourly_forecast'][1]['snow'];
  61. $snow = $parsed_json['metric'];
  62. echo "Schnee ".$snow."mm"."\n";
  63.  
  64. $parsed_json = json_decode($json_string, true);
  65. $parsed_json = $parsed_json['hourly_forecast'][1];
  66. $zustand = $parsed_json['condition'];
  67. echo $zustand."\n";
  68.  
  69. $parsed_json = json_decode($json_string, true);
  70. $parsed_json = $parsed_json['hourly_forecast'][1];
  71. $regenwar = $parsed_json['pop'];
  72. echo "Regenrisiko ".$regenwar."%"."\n";
  73.  
  74. $parsed_json = json_decode($json_string, true);
  75. $parsed_json = $parsed_json['hourly_forecast'][1]['mslp'];
  76. $druck = $parsed_json['metric'];
  77. echo "Luftdruck ".$druck."hPa"."\n";
  78.  
  79. //---prepare a twitter text file for the twitter.php file
  80. $ze = fopen("/home/pi/domoticz/scripts/twitterwetter.txt", "w");
  81. fwrite ($ze, $stunde.":".$min." ".$tag.".".$monat.".".$jahr."\n");
  82. fwrite ($ze, $zustand."\n");
  83. fwrite ($ze, "Temp ".$temp."C"."\n");
  84. fwrite ($ze, "Wind ".$windspeed."km/h"." aus ");
  85. fwrite ($ze, $winddir." "."\n");
  86. fwrite ($ze, "Luftf. ".$humy."%"."\n");
  87. fwrite ($ze, "Regenrisiko ".$regenwar."% "."\n");
  88. fwrite ($ze, "Regen ".$regen."mm"."\n");
  89. fwrite ($ze, "Schnee ".$snow."mm"."\n");
  90. fwrite ($ze, "Druck ".$druck."hPa");
  91. fclose ($ze);
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement