Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $city="Budapest"; // Your city
- $country="hu"; // Two digit country code
- $url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&appid=2de143494c0b295cca9337e1e96b00e0&units=metric";
- $json=file_get_contents($url);
- $data=json_decode($json,true);
- $file = '/home/cs2d/sys/lua/weather.dat';
- $current = file_get_contents($file);
- $current .= $data['weather'][0]['main']."\n".$data['main']['temp']."\n";
- // Write the contents back to the file
- file_put_contents($file, $current);
- $lines = file($current, FILE_IGNORE_NEW_LINES);
- $remove = $current;
- foreach($lines as $key => $line)
- if(stristr($line, $remove)) unset($lines[$key]);
- $data = implode('\n', array_values($lines));
- $file = fopen($path);
- fwrite($file, $data);
- fclose($file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement