summaryrefslogtreecommitdiff
path: root/widgets/weather
diff options
context:
space:
mode:
authorMartin Schirrmacher <vdr.skinflatplus@schirrmacher.eu>2014-11-16 12:43:30 +0100
committerMartin Schirrmacher <vdr.skinflatplus@schirrmacher.eu>2014-11-16 12:43:30 +0100
commitefdb12a81dd96d913651b8b2bd5bbcbd8b135cbb (patch)
tree1c8b26612abe39c49fd494c32ea33554bcbaff55 /widgets/weather
parentff62c44e6cfdf5b015d04256341e950de76c6b92 (diff)
downloadskin-flatplus-efdb12a81dd96d913651b8b2bd5bbcbd8b135cbb.tar.gz
skin-flatplus-efdb12a81dd96d913651b8b2bd5bbcbd8b135cbb.tar.bz2
update widgets
Diffstat (limited to 'widgets/weather')
-rw-r--r--widgets/weather/GetLatLangFromCity.php25
-rw-r--r--widgets/weather/README9
-rw-r--r--widgets/weather/update_weather.config15
-rw-r--r--widgets/weather/update_weather.php38
4 files changed, 59 insertions, 28 deletions
diff --git a/widgets/weather/GetLatLangFromCity.php b/widgets/weather/GetLatLangFromCity.php
new file mode 100644
index 00000000..e05c1bc8
--- /dev/null
+++ b/widgets/weather/GetLatLangFromCity.php
@@ -0,0 +1,25 @@
+<?php
+
+$handle = fopen ("php://stdin","r");
+echo "Country (like DE for Germany): ";
+$country = fgets($handle);
+echo "City (like Berlin): ";
+$city = fgets($handle);
+
+// get lat & long from google maps
+$MAPSURL = "http://maps.googleapis.com/maps/api/geocode/json?address=".$city.",".$country."&sensor=false";
+$json = file_get_contents($MAPSURL);
+$data = json_decode($json, true);
+
+if( !isset($data['results'][0]) ) {
+ echo "no latitude and longitude find for: ".$city.",".$country." !\n";
+ exit;
+}
+$latitude = $data['results'][0]['geometry']['location']['lat'];
+$longitude = $data['results'][0]['geometry']['location']['lng'];
+
+echo "latitude: ".$latitude."\n";
+echo "longitude: ".$longitude."\n";
+echo "put these values in update_weather.config\n";
+
+?>
diff --git a/widgets/weather/README b/widgets/weather/README
new file mode 100644
index 00000000..956c7a26
--- /dev/null
+++ b/widgets/weather/README
@@ -0,0 +1,9 @@
+This widget provide information about weather for a defined location.
+
+Since the command usually needs long time to execute this is not called from skin flatPlus.
+You have to call the command from the system via cron or at system start.
+For example call the command from cron.daily.
+
+You need php5 with command line support for this widget. For example in Ubuntu you need the package "php5-cli".
+
+Please configur your location and others in update_weather.config. Use php-script "GetLatLangFromCity.php" to get latitude & longitude from your location.
diff --git a/widgets/weather/update_weather.config b/widgets/weather/update_weather.config
new file mode 100644
index 00000000..4a749212
--- /dev/null
+++ b/widgets/weather/update_weather.config
@@ -0,0 +1,15 @@
+[main]
+# use GetLatLangFromCity.php to get latitude/langitude
+Latitude = 52.5200066
+Longitude = 13.404954
+# location shown in Skin
+LocationSkin = "Berlin"
+# Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
+Units = "si"
+DegreeSign = "°C"
+# Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
+Lang = "de"
+# We have only 1000 api calls per day, so please only do one update per day!
+# Or request an own key for free at forecast.io
+ApiKey = "137f2d85a1f1db5762e5e073103541d2"
+
diff --git a/widgets/weather/update_weather.php b/widgets/weather/update_weather.php
index 8d2d8be9..d2d38c1e 100644
--- a/widgets/weather/update_weather.php
+++ b/widgets/weather/update_weather.php
@@ -1,38 +1,20 @@
<?php
-/*
- * USER CONFIG
- */
-$city = "Berlin";
-$country = "DE";
-$locationSkin = "Berlin"; // location shown in skin
-$units = 'si'; // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
-$degree_sign = "°C";
-$lang = 'de'; // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
-// We have only 1000 api calls per day, so please only do one update per day!
-// Or request an own key for free at forecast.io
-$api_key = '137f2d85a1f1db5762e5e073103541d2';
-
-/*
- * DO NOT CHANGE ANYTHING FROM HERE
- */
+$ini_array = parse_ini_file("./update_weather.config");
+
+$latitude = $ini_array['Latitude'];
+$longitude = $ini_array['Longitude'];
+$locationSkin = $ini_array['LocationSkin'];
+$units = $ini_array['Units'];
+$degree_sign = $ini_array['DegreeSign'];
+$lang = $ini_array['Lang'];
+$api_key = $ini_array['ApiKey'];
+
include('lib/forecast.io.php');
// delete old files
array_map('unlink', glob("weather.*"));
-// get lat & long from google maps
-$MAPSURL = "http://maps.googleapis.com/maps/api/geocode/json?address=".$city.",".$country."&sensor=false";
-$json = file_get_contents($MAPSURL);
-$data = json_decode($json, true);
-
-if( !isset($data['results'][0]) ) {
- echo "no latitude and longitude find for: ".$city.",".$country." !\n";
- exit;
-}
-$latitude = $data['results'][0]['geometry']['location']['lat'];
-$longitude = $data['results'][0]['geometry']['location']['lng'];
-
// forecast query
$forecast = new ForecastIO($api_key);