Advertisement
Guest User

Untitled

a guest
Dec 8th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.76 KB | None | 0 0
  1. <?php
  2. $city="Budapest"; // Your city
  3. $country="hu"; // Two digit country code
  4. $url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&appid=2de143494c0b295cca9337e1e96b00e0&units=metric";
  5. $json=file_get_contents($url);
  6. $data=json_decode($json,true);
  7. $file = '/home/cs2d/sys/lua/weather.dat';
  8. $current = file_get_contents($file);
  9. $current .= $data['weather'][0]['main']."\n".$data['main']['temp']."\n";
  10. // Write the contents back to the file
  11. file_put_contents($file, $current);
  12.  
  13. $lines = file($current, FILE_IGNORE_NEW_LINES);
  14. $remove = $current;
  15. foreach($lines as $key => $line)
  16.   if(stristr($line, $remove)) unset($lines[$key]);
  17.  
  18. $data = implode('\n', array_values($lines));
  19.  
  20. $file = fopen($path);
  21. fwrite($file, $data);
  22. fclose($file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement