@Didier-T
J'ai réussi à faire ce que je voulais avec ce script; mais je voudrais supprimer des fonctions pour qu'il ne fasse que le fichier "marker" et qu'il ne crée pas d'image... ? Je ne vois pas trop quoi enlever sans faire un massacre. 😉
Sinon ça fonctionne pour avoir les conditions meteo de n'importe quelle ville du monde, il suffit d'entrer les coordonées et le code de la ville sur le site wunderground.
Script modifié avec l'ajout de quelques villes et augmenté le temps pour les mises à jour:
#!/usr/bin/perl
# Copyright (c) 2006 John Graham-Cumming
# This file wraps xplanet to produce a background image in GNOME that
# shows the following:
#
# The time in various cities around the world
# A rectangular view of the entire world
# Night time imagery where it is currently dark
# Day time imagery adjusted for the correct season where it is light
# The weather in the same cities from wunderground.com
use strict;
use LWP::Simple;
my $root = '/tmp/';
my @images = ( 'xplanetemp.png', 'xplanetemp2.png' );
my $screen = '1280x720';
my $projection = 'ORTHOGRAPHIC';
my ( $latitude, $longitude ) = ( 47.17,8.36 );
my $config = 'config';
my $marker = 'marker';
my $update = 780;
my $image = 0;
open CONFIG, ">$root$config";
print CONFIG<<EOF;
[earth]
"Earth"
marker_file=$root$marker
night_map=night.jpg
marker_color=DarkGoldenrod1
marker_font=arial.ttf
min_radius_for_label=0
map=/home/raphix/.xplanet/images/earth.jpeg
cloud_map=/home/raphix/.xplanet/images/clouds.jpg
cloud_threshold=0
cloud_gamma=1.25
shade=80
bump_map=/home/raphix/.xplanet/images/bump_H2.png
bump_scale=0.15
magnify=40
EOF
close CONFIG;
my %cities = ( Londres => { lat => 51.50,
lon => -0.17,
tz => 'Europe/London',
loc => '03772',
con => '' },
Moscou => { lat => 55.75,
lon => 37.70,
tz => 'Europe/Moscow',
loc => '27612',
con => '' },
Tokyo => { lat => 35.75,
lon => 139.50,
tz => 'Asia/Tokyo',
loc => '47671',
con => '' },
'New York' => { lat => 40.70,
lon => -74.00,
tz => 'America/New_York',
loc => 'NY/New_York',
con => '' },
'Los Angeles' => { lat => 34.05,
lon => -118.23,
tz => 'America/Los_Angeles',
loc => 'CA/Los_Angeles',
con => '' },
Reykjavik => { lat => 64.15,
lon => -21.97,
tz => 'Atlantic/Reykjavik',
loc => '04030',
con => '' },
'Buenos Aires' => { lat => -34.67,
lon => -58.50,
tz => 'America/Buenos_Aires',
loc => '87582',
con => '' },
Tunis => { lat => 36.83,
lon => 10.22,
tz => 'Africa/Tunis',
loc => '60715',
con => '' },
'Hong Kong' => { lat => 22.30,
lon => 114.17,
tz => 'Asia/Hong_Kong',
loc => '45007',
con => '' },
'Horgen' => { lat => 47.17,
lon => 8.36,
tz => 'Europe/Paris',
loc => '06660',
con => '' },
'Ouarzazate' => { lat => 30.83,
lon => -6.16,
tz => 'Africa/Ouarzazate',
loc => '60265',
con => '' },
'Anchorage' => { lat => 61.22,
lon => -149.90,
tz => 'America/Anchorage',
loc => 'AK/Anchorage',
con => '' },
'Bangkok' => { lat => 13.73,
lon => 100.50,
tz => 'Asia/Bangkok',
loc => '48456',
con => '' },
'Berlin' => { lat => 52.53,
lon => 13.42,
tz => 'Europe/Berlin',
loc => '10389',
con => '' },
'Le Caire' => { lat => 30.05,
lon => 31.25,
tz => 'Africa/Cairo',
loc => '62366',
con => '' },
'Cayenne' => { lat => 4.92,
lon => -52.30,
tz => 'America/Cayenne',
loc => '81405',
con => '' },
'Dakar' => { lat => 14.63,
lon => -17.45,
tz => 'Africa/Dakar',
loc => '61641',
con => '' },
'Damas' => { lat => 33.50,
lon => 36.32,
tz => 'Asia/Damascus',
loc => '40080',
con => '' },
'Istanbul' => { lat => 41.03,
lon => 28.95,
tz => 'Asia/Istanbul',
loc => '17060',
con => '' },
'Chicago' => { lat => 41.85,
lon => -87.65,
tz => 'America/Chicago',
loc => 'IL/Chicago',
con => '' },
'San Juan' => { lat => 18.48,
lon => -66.13,
tz => 'America/Puerto_Rico',
loc => '87311',
con => '' },
'La Mecque' => { lat => 21.45,
lon => 39.82,
tz => 'Asia/Riyadh',
loc => '41030',
con => '' },
);
my $weather_countdown = 0;
while ( 1 ) {
my $uptime = `uptime`;
chomp $uptime;
if ( $weather_countdown == 0 ) {
get_all_weather();
$weather_countdown = 30;
}
--$weather_countdown;
open MARKER, ">$root$marker";
print MARKER<<EOF;
-80 -45 "$uptime"
EOF
foreach my $city (sort keys %cities) {
my $con = ( $city =~ /London|Paris/)?$cities{$city}{con}:'';
my $lat1 = $cities{$city}{lat}-2;
print MARKER<<EOF;
$cities{$city}{lat} $cities{$city}{lon} "$city %H:%M $con" timezone=$cities{$city}{tz}
EOF
if ( $con eq '' ) {
print MARKER<<EOF;
$lat1 $cities{$city}{lon} "$cities{$city}{con}" symbolsize=0
EOF
}
}
close MARKER;
system( "xplanet -num_times 1 -output $root$images[$image] -geometry $screen -longitude $longitude -latitude $latitude -projection $projection -config $root$config" );
#system( "gconftool-2 -t str -s /desktop/gnome/background/picture_filename $root$images[$image]" );
$image = 1 - $image;
unlink( "$root$images[$image]" );
sleep( $update );
}
sub get_weather
{
my ( $location ) = @_;
my $base = 'http://www.wunderground.com/auto/rss_full/';
my $url = $base;
if ( $location =~ /\d/ ) {
$url .= 'global/stations/';
}
$url .= "${location}.xml?units=both";
my $weather = get( $url );
my $conditions;
if ( $weather =~
/Temperature: [^\/]+ \/ (-?\d+)[^\|]+ \| .+ \| Conditions: ([^\|]+) \|/ ) {
$conditions = "($1C: $2)";
}
return $conditions;
}
sub get_all_weather
{
foreach my $city (sort keys %cities) {
$cities{$city}{con} = get_weather( $cities{$city}{loc} );
print "$city weather is $cities{$city}{con}\n";
}
}