#! /usr/bin/perl -w

#
# Parts based on nwsxml.pl by Lucien Dunning
# TODO: Conversion of units. Currently the units are ignored

use strict;
use XML::Simple;
use LWP::UserAgent;
# Ideally we would use the If-Modified-Since header
# to reduce server load, but they ignore it
#use HTTP::Cache::Transparent;
use Getopt::Std;
use File::Basename;
use lib dirname($0);




our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);

my (%mythoutput,$value,$keyword);

my $name = 'Accu.com-Current';
my $version = 0.2;
my $author = 'Marcel Verpaalen';
# modified by gilles74 - mythtv-fr
#my $email = 'marcel.verpaalen@gmail.com';
my $email = ' ';

# Basic options
     my $updateTimeout = 120*60;
     my $retrieveTimeout = 30;
     my @types = ('cclocation', 'station_id', 'copyright', 'daycode',
        	'observation_time', 'weather', 'temp', 'relative_humidity',
        	'wind_dir', 'pressure', 'visibility', 'weather_icon',
        	'appt', 'wind_spdgst', 
	'3dlocation', 
        	'date-0', 'icon-0', 'low-0', 'high-0',
        	'date-1', 'icon-1', 'low-1', 'high-1', 
        	'date-2', 'icon-2', 'low-2', 'high-2', 'updatetime',
	'6dlocation', 
		'date-3', 'icon-3', 'low-3', 'high-3',
        	'date-4', 'icon-4', 'low-4', 'high-4',
        	'date-5', 'icon-5', 'low-5', 'high-5', 
		);

      my $dir = "./";


# definition des options
getopts('Tvtlu:d:');

     # option v  -  script informations
          if (defined $opt_v) {
              print "$name,$version,$author,$email\n";
          exit 0;
          }
     # option T  -  delay values
          if (defined $opt_T) {
              print "$updateTimeout,$retrieveTimeout\n";
          exit 0;
          }
     # option l -search location
          if (defined $opt_l) {
              my $search = shift;
              my $location_base_url = 'http://forecastfox.accuweather.com/adcbin/forecastfox/locate_city.asp?location=';

              my $ua = LWP::UserAgent->new;
                 $ua->timeout(20);
                 $ua->env_proxy;
                 $ua->agent('Mozilla/5.0');

              my $response = $ua->get($location_base_url . $search);
                 die unless defined $response;
              my $xml = XMLin($response->decoded_content );

              if (!$xml) {
                   die "Not xml";
              }

              foreach my $item (@{$xml->{citylist}->{location}}){
                 printf "%s::%s", $item->{location},  $item->{city} . ", " .  $item->{state} . "\n" ; 
              }
              exit 0;
          }


    # Option t  - give used items 
         if (defined $opt_t) {
             foreach (@types) {print; print "\n";}
             exit 0;
         }

   # Option d  - defined the directory for the cache
        if (defined $opt_d) {
             $dir = $opt_d;
        }



# main program - download data

my $locid = shift;

# we get here, we're doing an actual retrieval, everything must be defined
	if (!(defined $opt_u && defined $locid && !$locid eq "")) {
	    die "Invalid usage";
	}

	my $units = $opt_u;

	my $type;
foreach $type (@types){$mythoutput{$type}='N/A' ;};

	my $url = 'http://forecastfox.accuweather.com/adcbin/forecastfox/weather_data.asp?metric=1&partner=forecastfox&location=';

	my $base_url = "$url$locid" ;


	 my $ua = LWP::UserAgent->new;
	 $ua->timeout(20);
 	$ua->env_proxy;
 #	$ua->put_ToCharset("iso-8859-1");
 #	$ua->put_from_ToCharset("utf-8"); 	
 #	$ua->ConvertFile();
 	$ua->agent('Mozilla/5.0');


 	my $response = $ua->get($base_url);
 
 #	if ($response->is_success) {

#	 }
#	 else {
# 	    die $response->status_line;
#	 }
 

	my $xml = XMLin($response->decoded_content );

	if (!$xml) {
	    die "Not xml";
	}

    # Conversion of keys accuweather->Myth
           my %conv  = ("temperature","temp",
			"weathertext","weather",
			"winddirection","wind_dir",
			"windgusts","wind_gust",
			"humidity", "relative_humidity",
			"visibility","visibility",
			"pressure","pressure",
			"realfeel","appt",
			"weathericon","weather_icon",
			"windspeed","wind_spdgst");


    # header data
           $mythoutput{"copyright"} = $xml->{copyright};
           $mythoutput{"station_id"} = $locid ;
           $mythoutput{"cclocation"} = $xml->{local}->{city} . ", " . $xml->{local}->{state} ;
           $mythoutput{"3dlocation"} = $xml->{local}->{city} . ", " . $xml->{local}->{state} ;
           $mythoutput{"6dlocation"} = $xml->{local}->{city} . ", " . $xml->{local}->{state} ;
           $mythoutput{"observation_time"} = "Observations du : " . $xml->{forecast}->{day}->[0]->{obsdate} . " " . $xml->{local}->{time} ;
           $mythoutput{"updatetime"} = "Prévisions du : " . $xml->{forecast}->{day}->[0]->{obsdate} . " " . $xml->{local}->{time} ;


   # Current conditions
	foreach my $key (keys (%{$xml->{currentconditions}})){

	   if ( exists $conv {$key}  ) {
	        $value = $xml->{currentconditions}->{$key};
	   if (ref($value) eq 'HASH'){
		$mythoutput{$conv {$key}} = $value->{content} ;}
	   else {
		$mythoutput{$conv {$key}} = $value ;
		}
	      #printf $conv {$key}  . "::%s" . "\n" , $xml->{currentconditions}->{$key} ;
	   }  
	   else {
		# printf "Not processed: " . $key . "=%s" . "\n" ,  $xml->{currentconditions}->{$key} ;
	        }
           }

  # day mappings to be made
        my %daycodes = ("Monday","Lundi",
	                "Tuesday","Mardi",
	                "Wednesday","Mercredi",
	                "Thursday","Jeudi",
	                "Friday","Vendredi",
	                "Saturday","Samedi",
	                "Sunday","Dimanche");

  # conversions days/ mapping
        if ( exists $daycodes { $mythoutput {"daycode"}}) {
	      $mythoutput {"daycode"} = $daycodes {$mythoutput {"daycode"}}; }
        else { $mythoutput {"daycode"} = "Jour Inconnu" ; };
    
  # wind direction mappings to be made
        my %wind_dirs = ("N","Nord",
			"NNE", "Nord-nord-est",
			"NE","Nord-est",
			"ENE", "Est-nord-est",
	                "E","Est",
			"ESE","Est-sud-est",
			"SE", "Sud-est",
			"SSE","Sud-sud-est",
	                "S","Sud",
			"SSW","Sud-sud-ouest",
			"SW", "Sud-ouest",
			"WSW","Ouest-sud-ouest",
			"W","Ouest",                
			"WNW","Ouest-nord-ouest",
	                "NW","Nord-ouest",
			"NNW","Nord-nord-ouest",
			"CLM","Variable");

  # conversions wind direction/ mapping
        if ( exists $wind_dirs { $mythoutput {"wind_dir"}}) {
	      $mythoutput {"wind_dir"} = $wind_dirs {$mythoutput {"wind_dir"}}; }
        else  { };
    
  #weathers mappings to be made
  #Translation available:"English","French","Dutch","German","Traditional chinese","Slovak","Russian","Greek"
  #By The_RedBurn    http://extensions.geckozone.org/The_RedBurn

       my %weathers = ("Cloudy and Cold","Nuageux et froid",
	"A Few Clouds","Quelques nuages",#  				"Weinig bewolking","gering bewölkt","??","Malá obla?nos?","???????????????? ??????","????????? ????"
	"AM Clouds / PM Sun","Nuageux dans la matinée / Soleil dans l'après-midi",#  				"Bewolkt in de ochtend, zon in de middag","vormittags bewölkt, nachmittags sonnig","????/???","Dopoludnia zamra?ené / Popoludní slne?no","?????? ?? ??????? / ?????? ????? ???????","?? ????????? / ?? ??????????"
	"AM Clouds / PM Sun / Wind","Nuageux dans la matinée / Soleil dans l'après-midi / Vent",#  				"Bewolkt in de ochtend, zon en wind in de middag","vormittags bewölkt, nachmittags sonnig und windig","??????????","Dopoludnia zamra?ené / Popoludní slne?no / Vietor","?????? ?? ??????? / ?????? ????? ??????? / ?????","?? ????????? / ?? ?????????? / ??????"
	"AM Drizzle","Bruine dans la matinée",#  				"Motregen in de ochtend","vormittags Nieselregen","?????","Dopoludnia mrholenie","???????? ?? ???????","?? ??????"
	"AM Fog / PM Sun","Brouillard dans la matinée / Soleil dans l'après-midi",#  				"Mist in de ochtend, zon in de middag","vormittags Nebel, nachmittags sonnig",,,,
	"AM Fog / PM Clouds","Brouillard dans la matinée / Nuageux dans l'après-midi",#  				,,,,,
	"AM Light Rain","Légère pluie dans la matinée",#  				"Lichte regen in de ochtend","vormittags leichter Regen","????","Dopoludnia slabý dá??","?????? ????? ?? ???????","?? ??????? ?????"
	"AM Light Rain / Wind","Légère pluie dans la matinée / Vent",#  				"Lichte regen en wind in de ochtend","vormittags leichter Regen / Wind","???????","Dopoludnia slabý dá?? / Vietor","?????? ????? ?? ??????? / ?????","?? ??????? ????? / ??????"
	"AM Light Snow","Légères chutes de neige dans la matinée",#  				"Lichte sneeuw in de ochtend","vormittags leichter Schneefall","????","Dopoludnia slabé sne?enie","?????? ???? ?? ???????","?? ??????? ??????????"
	"AM Light Snow / Wind","Légères chutes de neige dans la matinée / Vent",#  				"Lichte sneeuw en wind in de ochtend","vormittags leichter Schneefall und windig","???????","Dopoludnia slabé sne?enie / Vietor","?????? ???? ?? ??????? / ?????","?? ??????? ?????????? / ??????"
	"AM Light Wintry Mix","Légères précipitations hivernales dans la matinée",#  				"Lichte winterse neerslag in de ochtend","vormittags leichte Mischung aus Schnee und Regen","???????","Dopoludnia sychravo","?????? ????? ? ????????? ? ???? ?? ???????","?? ??????? ?????????"
	"AM Rain","Pluie dans la matinée",#  				"Regen in de ochtend","vormittags Regen","????","Dopoludnia dá??","????? ?? ???????","?? ?????"
	"AM Rain / Ice","Pluie dans la matinée / Glace",#  				"Regen / IJzel in de ochtend","vormittags Regen / Eis","???????","Dopoludnia dá?? / ?ad","????? ?? ??????? / ???","?? ????? / ?????"
	"AM Rain / Snow","Pluie dans la matinée / Neige",#  				"Regen / sneeuw in de ochtend","vormittags Regen / Schnee","???????","Dopoludnia dá?? / Sne?enie","????? ?? ??????? / ????","?? ????? / ?????"
	"AM Rain / Snow / Wind","Pluie dans la matinée / Neige / Vent",#  				"Regen / sneeuw en wind in de ochtend","vormittags Regen / Schnee / Wind","??????????","Dopoludnia dá?? / Sne?enie / Vietor","????? ?? ??????? / ???? / ?????","?? ????? / ????? / ??????"
	"AM Rain / Snow Showers","Pluie / Chutes de neige dans la matinée",#  				"Regen- en sneeuwbuien in de ochtend","vormittags Regen / Schneeschauer","???????","Dopoludnia dá?? / Snehové prehánky","????? ?? ??????? / ???????? ????","?? ????? / ????????????"
	"AM Rain / Wind","Pluie dans la matinée / Vent",#  				"Regen / wind in de ochtend","vormittags Regen / Wind","???????","Dopoludnia dá?? / Vietor","????? ?? ??????? / ?????","?? ????? / ??????"
	"AM Showers","Averses dans la matinée",#  				"Buien in de ochtend","vormittags Regenschauer","????","Dopoludnia prehánky","???????? ????? ?? ???????","?? ?????????"
	"AM Showers / Wind","Averses dans la matinée / Vent",#  				"Buien / wind in de ochtend","vormittags Regenschauer / Wind","???????","Dopoludnia prehánky / Vietor","???????? ????? ?? ??????? / ?????","?? ????????? / ??????"
	"AM Snow","Neige dans la matinée",#  				"Sneeuw in de ochtend","vormittags Schnee","????","Dopoludnia sne?enie","???? ?? ???????","?? ?????"
	"AM Snow Showers","Chutes de neige dans la matinée",#  				"Sneeuwbuien in de ochtend","vormittags Schneeschauer","????","Dopoludnia snehové prehánky","???????? ???? ?? ???????","?? ????????????"
	"AM Snow Showers / Wind","Chutes de neige dans la matinée / Vent",#  				"Sneeuwbuien / wind in de ochtend","vormittags Schneeschauer / Wind","???????","Dopoludnia snehové prehánky / Vietor","???????? ???? ?? ??????? / ?????","?? ???????????? / ??????"
	"AM T-Storms","Orages dans la matinée",#  				"Onweersbuien in de ochtend","vormittags Gewitter","??????","Dopoludnia búrky","????? ?? ???????","?? ??????????"
	"AM Wintry Mix","Précipitations hivernales dans la matinée",#  				"Winterse neerslag in de ochtend","vormittags Mischung aus Schnee und Regen","????","Dopoludnia chladno a sychravo","????? ? ????????? ? ???? ?? ???????","?? ?????????"
	"Blowing Sand and Windy","Rafales de sable et Vent",#  				"Opwaaiend zand en winderig","Sandwehen und windig","????","Zvírený piesok a veterno","???????? ???? ? ???????","??????????"
	"Blowing Snow","Rafales de neige",#  				"Opwaaiende sneeuw","Schneewehen","??","Zvírený sneh (tvorba závejov)","??????","???????????"
	"Clear","Ciel dégagé",#  				"Onbewolkt","wolkenlos","??","Jasno","????","???????"
	"Clouds Early / Clearing Late","Nuageux d'abord / Éclaircie ensuite",#  				"Eerst bewolkt, later opklaringen","anfangs bewölkt, später aufklarend","???/???","Spo?iatku obla?no / Neskôr jasno","?????? ????? / ???? ???????","????????? ????? / ??????? ????????"
	"Cloudy","Nuageux",#  				"Bewolkt","bewölkt","?","Zamra?ené","???????","?????????"
	"Cloudy / Wind","Nuageux / Vent",#  				"Bewolkt / wind","bewölkt / Wind","????","Zamra?ené / Vietor","??????? / ?????","????????? / ??????"
	"Cloudy and Windy","Nuageux et Venteux",#  				"Bewolkt en winderig","bewölkt und windig","????","Zamra?ené a veterno","??????? ? ???????","????????? ?? ?????"
	"Drifting Snow","Rafales de neige",#  				,,,,,
	"Drizzle","Bruine",#  				"Motregen","Nieselregen","???","Mrholenie","????????","??????"
	"Drizzle / Fog","Bruine / Brouillard",#  				,,,,,
	"Fair","Beau",#  				"Licht bewolkt","heiter","???","Pekne","????","???????"
	"Fair and Windy","Beau et Venteux",#  				"Licht bewolkt en winderig","heiter und windig","??????","Pekne a veterno","???? ? ???????","??????? ?? ?????"
	"Few Showers","Quelques averses",#  				"Een paar buien","einige Regenschauer","????","Ojedinelé prehánky","??????????????? ???????? ?????","???????? ??????"
	"Few Showers / Wind","Quelques averses / Vent",#  				"Een paar buien / wind","einige Regenschauer / Wind","???????","Ojedinelé prehánky / Vietor","??????????????? ???????? ????? / ?????","????? ??????/ ??????"
	"Few Snow Showers","Quelques chutes de neige",#  				"Een paar sneeuwbuien","einige Schneeschauer","????","Ojedinelé snehové prehánky","??????????????? ???????? ????","????? ????????????"
	"Few Snow Showers / Wind","Quelques chutes de neige / Vent",#  				"Een paar sneeuwbuien / wind","einige Schneeschauer / Wind","???????","Ojedinelé snehové prehánky / Vietor","??????????????? ???????? ???? / ?????","????? ???????????? / ??????"
	"Flurries","Chutes de neige fondante",#  				"Stuifsneeuw","Böen","??","Nepriaznivo - ?lapkanica","?????","???????"
	"Flurries / Wind","Chutes de neige fondante / Vent",#  				"Stuifsneeuw / wind","Böen / Wind","?????","Nepriaznivo - ?lapkanica / Vietor","????? / ?????","??????? / ??????"
	"Fog","Brouillard",#  				"Mist","Nebel","?","Hmla (vidite?nos? do 1 km)","?????","??????"
	"Fog / Clouds","Brouillard / Ciel se couvrant",#  				,,,,,
	"Fog Early / Clearing Late","Brouillard d'abord / Éclaircie ensuite",#  				,,,,,
	"Foggy","Brouillard",#  				,,,,,
	"Freezing Rain","Pluie verglaçante",#  				,,,,"??????? ?????","???????? ?????"
	"Haze","Légère brume",#  				"Heiigheid","Dunst","?","Hmla (vidite?nos? do 10 km)","?????","????????"
	"Heavy Drizzle","Forte bruine",#  				,,,,"??????? ????????","?????? ??????"
	"Heavy Rain","Forte pluie",#  				"Zware regen","starker Regen","??","Silný da??","??????? ?????","?????????"
	"Heavy Rain / Wind","Forte pluie / Vent",#  				"Zware regen / wind","starker Regen / Wind","?????","Silný da?? / Vietor","??????? ????? / ?????","????????? / ??????"
	"Heavy Rain Shower","Fortes averses",#  				"Zware regenbui","starker Regenschauer","???","Silné da??ové prehánky","?????????? ???????? ?????","?????? ?????????"
	"Heavy Rain Shower and Windy","Fortes averses et Vent",#  				"Zware regenbui en winderig","starker Regenschauer und windig","??????","Silné da??ové prehánky a veterno","?????????? ???????? ????? ? ???????","?????? ????????? ?? ?????"
	"Heavy Snow","Fortes chutes de neige",#  				"Zware sneeuwval","starker Schneefall","??","Silné sne?enie","??????? ????","?????? ??????????"
	"Heavy T-Storm","Orage violent",#  				"Zware onweersbui","starke Gewitter","???","Silné búrky",,
	"Heavy T-Storm and Windy","Orage violent et Vent",#  				"Zware onweersbui en winderig","starke Gewitter und windig","??????","Silné búrky a veterno","??????? ????? ? ???????","?????? ????????? ?? ?????"
	"Heavy T-Storms","Orages violents",#  				"Zware onweersbuien","starke Gewitter","???","Silné búrky","??????? ?????","?????? ?????????"
	"Heavy T-Storms / Wind","Orages violents / Vent",#  				"Zware onweersbuien / wind","starke Gewitter / Wind","??????","Silné búrky / Vietor","??????? ????? / ?????","?????? ????????? / ??????"
	"Heavy Rain / Freezing Rain","Forte pluie / Pluie verglaçante",#  				"Zware regen / IJzel","starker Regen / Eisregen","?????","Silný dá?? / Mrznúci dá??","??????? ????? / ??????? ?????","??????? ?????? / ???????? ?????"
	"Ice to Rain","Givre puis Pluie",#  				"IJsregen, overgaand in regen","Eisregen, in Regen übergehend","????","Mrznúci dá?? meniaci sa na dá??","???? ? ??????","????? ?? ?????"
	"Iso T-Storms / Wind","Orages isolés / Vent",#  				"Geïsoleerde onweersbuien / wind","vereinzelt Gewitter / Wind","???????","Ob?asné búrky / Vietor","????? ????????, ?? ???????????? / ?????","??????????? ?????????? / ??????"
	"Isolated T-Storms","Orages isolés",#  				"Geïsoleerde onweersbuien","vereinzelt Gewitter","????","Ob?asné búrky","????? ????????, ?? ????????????","??????????? ??????????"
	"Light Drizzle","Légère bruine",#  				"Lichte motregen","leichter Nieselregen","??","Slabé mrholenie","?????? ????????","??????? ??????"
	"Light Freezing Drizzle","Légère bruine verglaçante",#  				,,,,"?????? ??????? ????????","??????? ???????? ??????"
	"Light Freezing Rain","Légère pluie verglaçante",#  				,,,,"?????? ??????? ?????","??????? ???????? ?????"
	"Light Rain","Légère pluie",#  				"Lichte regen","leichter Regen","??","Slabý dá??","?????? ?????","??????? ?????"
	"Light Rain / Fog","Légère pluie / Brouillard",#  				,,,,,
	"Light Rain / Freezing Rain","Légère pluie / Pluie verglaçante",#  				"Lichte regen of ijzel","leichter bis gefrierender Regen","?????","Slabý dá?? / Mrznúci dá??","?????? ????? / ??????? ?????","??????? ????? / ???????? ?????"
	"Light Rain / Wind","Légère pluie / Vent",#  				"Lichte regen en wind","leichter Regen / Wind","?????","Slabý dá?? / Vietor","?????? ????? / ?????","??????? ????? / ??????"
	"Light Rain and Fog","Légère pluie et Brouillard",#  				,,,,,
	"Light Rain and Freezing Rain","Légère pluie et Pluie verglaçante",#  				,,,,"?????? ? ??????? ?????","??????? ????? ??? ???????? ?????"
	"Light Rain and Windy","Légère pluie et Vent",#  				"Lichte regen / wind","leichter Regen und Wind","?????","Slabý dá?? a veterno","?????? ????? ? ???????","??????? ????? ?? ?????"
	"Light Rain Shower","Légères averses",#  				"Lichte regenbui","leichter Regenschauer","???","Slabé da??ové prehánky","?????? ???????? ?????","??????? ?????????"
	"Lgt.rainshower","Légères averses",#  				"Lichte regenbui","leichter Regenschauer","???","Slabé da??ové prehánky","?????? ???????? ?????","??????? ?????????"
	"Light Rain Shower and Fog","Légère pluie et brouillard",#  				,,,,,
	"Light Rain Shower and Windy","Légères averses et Vent",#  				"Lichte regenbui en winderig","leichter Regenschauer und windig","?????","Slabé da??ové prehánky / Veterno","?????? ???????? ????? ? ???????","??????? ????????? ?? ?????"
	"Light Rain with Thunder","Légère pluie avec tonnerre",#  				"Lichte regen met onweer","leichter Regen mit Donner","????","Slabý dá?? s búrou","?????? ????? ? ??????","???????? ????? ?? ?????????"
	"Light Snow","Légères chutes de neige",#  				"Lichte sneeuwval","leichter Schneefall","??","Slabé sne?enie","?????? ????","??????? ??????????"
	"Light Snow / Fog","Légères chutes de neige / Brouillard",#  				,,,,,
	"Light Snow / Wind","Légère neige / Vent",#  				"Lichte sneeuw / wind","leichter Schneefall / Wind","?????","Slabé sne?enie / vietor","?????? ???? / ?????","??????? ?????????? / ??????"
	"Light Snow and Fog","Légère neige et Brouillard",#  				"Lichte sneeuwval en mist","leichter Schneefall und Nebel","????","Slabé sne?enie a hmla (vidite?nos? do 1 km)","?????? ???? ? ?????","??????? ?????????? ??? ??????"
	"Light Snow Grains","Légers granules de neige",#  				"Lichte korrelsneeuw","leichtes Schneegrieseln","???","Slabé snehové zrná","?????? ??????? ?????","???????? ???????"
	"Light Snow Grains and Fog","Légers granules de neige et Brouillard",#  				,,,,,
	"Light Snow Late","Légères chutes de neige",#  				"Later lichte sneeuwval","später leichter Schneefall","????","Slabé neskoré sne?enie","?????? ???? ???????","??????? ?????????? ????"
	"Light Snow Shower","Légères chutes de neige",#  				"Lichte sneeuwbui","leichter Schneeschauer","???","Slabé snehové prehánky","?????? ???????? ????","??????? ??????????"
	"Light Snow Shower / Wind","Légères chutes de neige / Vent",#  				"Lichte sneeuwbui / wind","leichter Schneeschauer / Wind","?????","Slabé snehové prehánky / Vietor","?????? ???????? ???? / ?????","??????? ?????????? / ??????"
	"Mist","Brume",#  				"Nevel","Nebel","?","Dymno bez vodných pár (vidite?nos? do 1 km)","????????","????????"
	"Mostly Clear","Ciel plutôt dégagé",#  				"Overwegend onbewolkt","überwiegend wolkenlos","????","Preva?ne jasno","? ???????? ????","?????? ???????"
	"Mostly Clear / Wind","Ciel plutôt dégagé / Vent",#  				"Overwegend onbewolkt / wind","überwiegend wolkenlos / Wind","??????","Preva?ne jasno / Vietor","? ???????? ???? / ?????","?????? ??????? / ??????"
	"Mostly Cloudy","Plutôt nuageux",#  				"Overwegend bewolkt","überwiegend bewölkt","????","Preva?ne zamra?ené","??????? ? ????????????","?????? ?????????"
	"Mostly Cloudy / Wind","Plutôt nuageux / Vent",#  				"Overwegend bewolkt / wind","überwiegend bewölkt / Wind","??????","Preva?ne zamra?ené / Vietor","??????? ? ???????????? / ?????","?????? ????????? / ??????"
	"Mostly Cloudy and Windy","Plutôt nuageux et Venteux",#  				"Overwegend bewolkt en winderig","überwiegend bewölkt und windig","???????","Preva?ne zamra?ené a veterno","??????? ? ???????????? ? ???????","?????? ????????? ?? ?????"
	"Mostly Sunny","Plutôt ensoleillé",#  				"Overwegend zonnig","überwiegend sonnig","????","Preva?ne slne?no","? ???????? ????????","?????? ???????????"
	"Mostly Sunny / Wind","Plutôt ensoleillé / Vent",#  				"Overwegend zonnig / wind","überwiegend sonnig / Wind","??????","Preva?ne slne?no / Vietor","? ???????? ???????? / ?????","?????? ??????????? / ??????"
	"Partly Cloudy","Passages nuageux",#  				"Licht bewolkt","teilweise wolkig","??","Obla?no","????????? ??????????","??????? ?????????"
	"Partly Cloudy / Wind","Passages nuageux / Vent",#  				"Licht bewolkt / wind","teilweise wolkig / Wind","?????","Obla?no / Vietor","????????? ?????????? / ?????","??????? ????????? / ??????"
	"Partly Cloudy and Windy","Passages nuageux et Vent",#  				"Licht bewolkt en winderig","teilweise wolkig und windig","?????","Obla?no a veterno","????????? ?????????? ? ???????","??????? ????????? ?? ?????",
	"Partly Sunny","Partiellement ensoleillé",# nouveau
	"Patches of Fog","Bancs de brouillard",#  				,,,,"??????? ?????","??????? ???????"
	"PM Drizzle","Bruine dans l'après-midi",#  				"In de middag motregen","nachmittags Nieselregen","?????","Popoludní mrholenie","???????? ????? ???????","?? ??????"
	"PM Fog","Brouillard dans l'après-midi",#  				,,,,,
	"PM Light Rain","Légère pluie dans l'après-midi",#  				"In de middag lichte regen","nachmittags leichter Regen","????","Popoludní slabý dá??","?????? ????? ????? ???????","?? ??????? ?????"
	"PM Light Rain / Ice","Légère pluie dans l'après-midi / Verglas",#  				"In de middag lichte regen / ijsregen","nachmittags leichter Regen / Eis","???????","Popoludní slabý dá?? / ?ad","?????? ????? ????? ??????? / ???","?? ??????? ????? / ?????"
	"PM Light Rain / Wind","Légère pluie dans l'après-midi / Vent",#  				"In de middag lichte regen / wind","nachmittags leichter Regen / Wind","???????","Popoludní slabý dá?? / Vietor","?????? ????? ????? ??????? / ?????","?? ??????? ????? / ??????"
	"PM Light Snow","Légères chutes de neige dans l'après-midi",#  				"In de middag lichte sneeuw","nachmittags leichter Schneefall","????","Popoludní slabé sne?enie","?????? ???? ????? ???????","?? ??????? ??????????"
	"PM Light Snow / Wind","Légères chutes de neige dans l'après-midi / Vent",#  				"In de middag lichte sneeuw / wind","nachmittags leichter Schneefall / Wind","???????","Popoludní slabé sne?enie / Vietor","?????? ???? ????? ??????? / ?????","?? ??????? ?????????? / ??????"
	"PM Rain","Pluie dans l'après-midi",#  				"In de middag regen","nachmittags Regen","????","Popoludní dá??","????? ????? ???????","?? ?????"
	"PM Rain / Snow","Pluie / Neige dans l'après-midi",#  				"In de middag regen / sneeuw","nachmittags Regen / Schnee","???????","Popoludní dá?? / Sne?enie","????? ????? ??????? / ????","?? ????? / ?????"
	"PM Rain / Snow / Wind","Pluie / Neige / Vent dans l'après-midi",#  				"In de middag regen / sneeuw / wind","nachmittags Regen / Schnee / Wind","??????????","Popoludní dá?? / Sne?enie / Vietor","????? ????? ??????? / ???? / ?????","?? ????? / ????? / ??????"
	"PM Rain / Snow Showers","Pluie / Chutes de neige dans l'après-midi",#  				"In de middag regen / sneeuwbuien","nachmittags Regen / Schneeschauer","???????","Popoludní dá?? / Snehové prehánky","????? ????? ??????? / ???????? ????","?? ????? / ????????????"
	"PM Showers","Averses dans l'après-midi",#  				"In de middag buien","nachmittags Regenschauer","????","Popoludní prehánky","???????? ????? ????? ???????","?? ??????"
	"PM Showers / Wind","Averses / Vent dans l'après-midi",#  				"In de middag buien / wind","nachmittags Regenschauer / Wind","???????","Popoludní prehánky / Vietor","???????? ????? ????? ??????? / ?????","?? ?????? / ??????"
	"PM Snow","Chutes de neige dans l'après-midi",#  				"In de middag sneeuw","nachmittags Schneefall","????","Popoludní sne?enie","???? ????? ???????","?? ?????"
	"PM Snow / Wind","Chutes de neige dans l'après-midi / Vent",#  				"In de middag sneeuw / wind","nachmittags Schneefall / Wind","???????","Popoludní sne?enie / Vietor","???? ????? ??????? / ?????","?? ????? / ??????"
	"PM Snow Showers","Chutes de neige dans l'après-midi",#  				"In de middag sneeuwbuien","nachmittags Schneeschauer","????","Popoludní snehové prehánky","???????? ???? ????? ???????","?? ????????????"
	"PM Snow Showers / Wind","Chutes de neige dans l'après-midi / Vent",#  				"In de middag sneeuwbuien / wind","nachmittags Schneeschauer / Wind","???????","Popoludní snehové prehánky / Vietor","???????? ???? ????? ??????? / ?????","?? ???????????? / ??????"
	"PM T-Showers","Averses orageuses dans l'après-midi",#  				,,,,,
	"PM T-Storms","Orages dans l'après-midi",#  				"In de middag onweersbuien","nachmittags Gewitter","??????","Popoludní búrky","????? ????? ???????","?? ??????????"
	"PM Wintry Mix","Précipitations hivernales dans l'après-midi",#  				"In de middag winterse neerslag","nachmittags Mischung aus Schnee und Regen","??????","Popoludní chladno a sychravo","????? ? ????????? ? ???? ????? ???????","?? ?????????"
	"Rain","Pluie",#  				"Regen","Regen","?","Dá??","?????","?????"
	"Rain / Freezing Rain","Pluie / Pluie verglaçante",#  				"Regen / IJzel","Regen / Eisregen","?????","Dá?? / Mrznúci dá??","????? / ??????? ?????","????? / ???????? ?????"
	"Rain / Sleet","Pluie / Granules de glace",#  				"Regen / natte sneeuw","Regen / Schneeregen","????","Dá?d / Krúpy ","????? / ???????","????? / ?????????"
	"Rain / Snow","Pluie / Neige",#  				"Regen / sneeuw","Regen / Schnee","????","Dá?? / Sne?enie","????? / ????","????? / ?????"
	"Rain / Snow / Wind","Pluie / Neige / Vent",#  				"Regen / sneeuw / wind","Regen / Schnee / Wind","???????","Dá?? / Sne?enie / Vietor","????? / ???? / ?????","????? / ????? / ??????"
	"Rain / Snow Showers","Pluie / Chutes de neige",#  				"Regen / sneeuwbuien","Regen / Schneeschauer","????","Dá?? / Snehové prehánky","????? / ???????? ????","????? / ????????????"
	"Rain / Snow Showers / Wind","Pluie / Chutes de neige / Vent",#  				"Regen / sneeuwbuien / wind","Regen / Schneeschauer / Wind","???????","Dá?? / Snehové prehánky / Vietor","????? / ???????? ???? / ?????","????? / ???????????? / ??????"
	"Rain / Snow Showers Late","Pluie / Chutes de neige",#  				"Regen / later sneeuwbuien","später Regen / Schneeschauer","???????","Dá?? / Neskôr snehové prehánky","????? / ???????? ???? ???????","????? / ???????????? ????"
	"Rain / Thunder","Pluie / Tonnerre",#  				"Regen / onweer","Regen / Donner","????","Dá?? / Hrmenie","????? / ????","????? / ????????"
	"Rain / Thunder / Wind","Pluie / Tonnerre / Vent",#  				"Regen / onweer / wind","Regen / Donner / Wind","???????","Dá?? / Hrmenie / Vietor","????? / ???? / ?????","????? / ???????? / ??????"
	"Rain / Wind","Pluie / Vent",#  				"Regen / wind","Regen / Wind","????","Dá?? / Vietor","????? / ?????","????? / ??????"
	"Rain and Sleet","Pluie et Granules de glace",#  				"Regen en natte sneeuw","Regen und Graupelschauer","?????","Dá?? a krúpy","????? ? ???????","????? ??? ?????????"
	"Rain and Snow","Pluie et Neige",#  				"Regen en sneeuw","Regen und Schnee","???","Dá?? a sne?enie","????? ? ????","????? ??? ?????"
	"Rain Shower","Averses",#  				"Regenbui","Regenschauer","??","Da??ové prehánky","???????? ?????","?????????"
	"Rain Shower and Windy","Averses et Vent",#  				"Regenbui en winderig","Regenschauer und windig","?????","Dá?? / ?lapkanica","???????? ????? ? ???????","????????? ?? ?????"
	"Rain to Snow","Pluie devenant neige",#  				"Regen overgaand in sneeuw","Regen, in Schnee übergehend","???","Dá?? so snehom","????? ?? ??????","????? ???? ?????"
	"Rain to Snow / Wind","Pluie devenant neige / Vent",#  				"Regen overgaand in sneeuw / wind","Regen, in Schnee übergehend / Wind","??????","Dá?d so snehom / Vietor ","????? ?? ?????? / ?????","????? ???? ????? / ??????"
	"Scattered Flurries","Chutes de neige fondante éparses",#  				"Hier en daar wat stuifsneeuw","stellenweise Böen","????","Ojedinelo ?lapkanica","???????? ?????","?????????? ???????"
	"Scattered Flurries / Wind","Chutes de neige fondante éparses / Vent",#  				"Hier en daar wat stuifsneeuw / wind","stellenweise Böen / Wind","???????","Ojedinelo ?lapkanica / Vietor","???????? ????? / ?????","?????????? ??????? / ??????"
	"Scattered Showers","Averses éparses",#  				"Hier en daar buien","stellenweise Regenschauer","????","Ojedinelé prehánky","???????? ???????? ?????","?????????? ??????"
	"Scattered Showers / Wind","Averses éparses / Vent",#  				"Hier en daar buien / wind","stellenweise Regenschauer / Wind","???????","Ojedinelé prehánky / Vietor","???????? ???????? ????? / ?????","?????????? ?????? / ??????"
	"Scattered Snow Showers","Alternance de chutes de neige",#  				"Hier en daar sneeuwbuien","stellenweise Schneeschauer","????","Ojedinelé snehové prehánky","???????? ???????? ????","?????????? ????????????"
	"Scattered Snow Showers / Wind","Chutes de neige éparses / Vent",#  				"Hier en daar sneeuwbuien / wind","stellenweise Schneeschauer / Wind","???????","Ojedinelé snehové prehánky / Vietor","???????? ???????? ???? / ?????","?????????? ???????????? / ??????"
	"Scattered Strong Storms","Orages violents épars",#  				"Hier en daar zware buien","stellenweise schwere Stürme","??????","Ojedinelé silné búrky","???????? ??????? ?????","?????????? ??????? ??????????"
	"Scattered T-Storms","Orages épars",#  								"Hier en daar onweersbuien","stellenweise Gewitter","????","Ojedinelé búrky","???????? ?????","?????????? ??????????"
	"Scattered T-Storms / Wind","Orages épars / Vent",#  								"Hier en daar onweersbuien / wind","stellenweise Gewitter / Wind","???????","Ojedinelé búrky / Vietor","???????? ????? / ?????","?????????? ?????????? / ??????"
	"Shallow Fog","Brouillard",#  								,,,,,
	"Showers","Averses",#  								"Buien","Regenschauer","????","Prehánky","???????? ?????","?????????"
	"Showers / Wind","Averses / Vent",#  								"Buien / wind","Regenschauer / Wind","?????","Prehánky / Vietor","???????? ????? / ?????","????????? / ??????"
	"Showers / Wind Late","Averses / Vent",#  								"Buien / later wind","später Regenschauer / Wind","???????","Prehánky / Neskôr veterno","???????? ????? / ????? ???????","????????? / ?????? ????"
	"Showers Early","Averses",#  								"Vroeg buien","anfangs Regenschauer","????","Spo?iatku prehánky","???????? ????? ?????","????????? ?????"
	"Showers in the Vicinity","Averses dans le voisinage",#  								"Buien in de nabijheid","Regenschauer in der Umgebung","?????","Blízka prehánka","???????? ????? ? ????????????","?????? ??? ???? ??????"
	"Showers Late","Averses",#  								"Later buien","später Regenschauer","????","Neskoré prehánky","???????? ????? ???????","????????? ????"
	"Sleet","Granules de glace ",#  				,,,,"???????","?????????"
	"Smoke","Fumée",#  				"Rook","Dunst","?","Dymová clona","???","??????"
	"Snow","Neige",#  				"Sneeuw","Schnee","?","Sne?enie","????","?????"
	"Snow / Wind","Neige / Vent",#  				"Sneeuw / wind","Schnee / Wind","????","Sne?enie / Vietor","???? / ?????","Snow / ??????"
	"Snow and Fog","Neige et Brouillard",#  				,,,,,
	"Snow and Ice to Rain","Neige et Glace puis Pluie",#  				"Sneeuw / ijsregen, overgaand in regen","Schnee und Eis, übergehend in Regen","?????","Sne?enie a mrznúci dá?? meniaci sa na dá??","???? ? ???? ? ??????","????? ??? ????? ?? ?????"
	"Snow Grains","Granules de neige",#  				"Korrelsneeuw","Schneegrieseln","??","Snehové zrná","??????? ?????","????????????"
	"Snow Shower","Chutes de neige",#  				"Sneeuwbui","Schneeschauer","??","Snehové prehánky","???????? ????","????????????"
	"Snow Shower / Wind","Chutes de neige / Vent",#  				"Sneeuwbuien / wind","Schneeschauer / Wind","?????","Snehové prehánky / Vietor","???????? ???? / ?????","???????????? / ??????"
	"Snow Shower / Wind Early","Chutes de neige / Vent",#  				"Sneeuwbuien / vroeg wind","anfangs Schneeschauer / Wind","??????","Snehové prehánky / Spo?iatku vietor","???????? ???? / ????? ?????","???????????? / ?????? ?????"
	"Snow Showers Early","Chutes de neige",#  				"Vroeg sneeuwbuien","anfangs Schneeschauer","????","Spo?iatku snehové prehánky","???????? ???? ?????","???????????? ?????"
	"Snow Showers Late","Chutes de neige",#  				"Later sneeuwbuien","später Schneeschauer","????","Neskoré snehové prehánky","???????? ???? ???????","???????????? ????"
	"Snow to Ice","Neige puis Verglas",#  				"Sneeuw, overgaand in ijsregen","Schnee, übergehend in Eis","???","Snehové krúpy","???? ? ??????","????? ?? ????"
	"Snow to Ice / Wind","Neige se transformant en glace / Vent",#  				"Sneeuw, overgaand in ijsregen / wind","Schnee, übergehend in Eis / Wind","??????","Snehové krúpy / Vietor","???? ? ?????? / ?????","????? ?? ???? / ??????"
	"Snow to Rain","Neige puis Pluie",#  				"Sneeuw, overgaand in regen","Schnee, übergehend in Regen","???","Sne?enie meniace sa na dá??","???? ? ??????","????? ?? ?????"
	"Snow to Rain / Wind","Neige puis Pluie / Vent",#  				"Sneeuw, overgaand in regen / wind","Schnee, übergehend in Regen / Wind","??????","Sne?enie meniace sa na dá?? / Vietor","???? ? ?????? / ?????","????? ?? ????? / ??????"
	"Snow to Wintry Mix","Neige puis Précipitations hivernales",#  				"Sneeuw, overgaand in natte sneeuw","Schnee, übergehend in Schneeregen oder Regen","??????","Chladno a sychravo so sne?ením","???? ? ????????? ? ?????","????? ?? ?????????"
	"Sprinkles","Averses",#  				"Lichte buitjes","leichter Regen","???","Prehánky","????????? ?????","?????????"
	"Strong Storms","Orages violents",#  				"Zware buien","starke Stürme","????","Silné búrky","??????? ?????","??????? ???????"
	"Strong Storms / Wind","Orages violents / Vent",#  				"Zware buien / wind","starke Stürme / Wind","???????","Silné búrky / Vietor","??????? ????? / ?????","??????? ??????? / ??????"
	"Sunny","Ensoleillé",#  				"Zonnig","sonnig","?","Slne?no","????????","???????????"
	"Sunny / Wind","Ensoleillé / Vent",#  				"Zonnig / wind","sonnig / Wind","????","Slne?no / Vietor","???????? / ?????","??????????? / ??????"
	"Sunny and Windy","Ensoleillé et Venteux",#  				"Zonnig / winderig","sonnig / windig","????","Slne?no / Vietor","???????? / ???????","??????????? / ??????"
	"T-Showers","Averses orageuses",#  				"Onweersbuien","stürmische Regenschauer","???","Prehánky","???????? ???????? ?????","??????????"
	"T-Showers / Wind","Averses orageuses / Vent",#  				"Onweersbuien / wind","stürmische Regenschauer / Wind","?????","Prehánky / Vietor","???????? ???????? ????? / ?????","?????????? / ??????"
	"T-Storm","Orage",#  				"Zware onweersbui","Gewitter","??","Búrka","?????","?????????"
	"T-Storms","Orages",#  				"Zware onweersbuien","Gewitter","????","Búrky","?????","??????????"
	"T-Storms / Wind","Orages / Vent",#  				"Zware onweersbuien / wind","Gewitter / Wind","???????","Búrky / Vietor","????? / ?????","?????????? / ??????"
	"T-Storms Early","Orages",#  				"Vroeg zware onweersbuien","anfangs Gewitter","??????","Spo?iatku búrky","????? ?????","?????????? ?????"
	"T-Storms Late","Orages",#  				"Later zware onweersbuien","später Gewitter","??????","Neskoré búrky","????? ???????","?????????? ????"
	"Thunder","Tonnerre",#  				"Onweer","Gewitter","??","Búrka","????","????????"
	"Thunder and Wintry Mix","Tonnerre et Précipitations hivernales",#  				"Onweer en Winterse neerslag","Gewitter und Mischung aus Schnee und Regen","???????","Chladno a sychravo s búrkou","???? ? ????? ? ????????? ? ????","???????? ??? ?????????"
	"Thunder in the Vicinity","Tonnerre dans le voisinage",#  				"Onweer in de nabijheid","Gewitter in der Umgebung","?????","Blízka búrka","???? ? ????????????","???????? ??? ???? ??????"
	"Unknown Precip","Précipitations",#  				,,,,,
	"Widespread Dust","Brume sèche",#  				"Stof, wijdverspreid","Schwebender Staub","???","Rozsiahle pra?no","???????? ??????? ????","??????? ?????"
	"Wintry Mix","Précipitations hivernales",#  				"Winterse neerslag","Mischung aus Schnee und Regen","????","Chladno a sychravo","????? ? ????????? ? ????","?????????"
	"Wintry Mix / Wind","Précipitations hivernales / Vent",#  				"Winterse neerslag / wind","Mischung aus Schnee und Regen / Wind","???????","Chladno a sychravo / Vietor","????? ? ????????? ? ???? / ?????","????????? / ??????"
	"Wintry Mix to Snow","Précipitations hivernales puis Neige",#  				"Natte sneeuw, overgaand in sneeuw","Mischung aus Schnee und Regen, übergehend in Schnee","??????","Chladno a sychravo so sne?ením","????? ? ????????? ? ????","????????? ?? ?????"
         "Overcast", "Brouillard bas",
	"Lgt.snow/fog", "légères chutes de neige et brouillard",
	"Snow/rain", "Pluie et neige mélée",
	"Snowshower","Averses de neige",
	"Lgt.snowshower", "Légères chutes de neige" ,
	"Light Fog", "Léger brouillard",
	"Ground Fog", "Stratus",
	"Some Clouds","Légèrement nuageux",
	"Clouds And Sun","Soleil et nuages",
	"Hvy.snowshower", "Fortes chutes de neige"
	);





  #conversions / mapping
    if ( exists $weathers { $mythoutput {"weather"}}) {
    	$mythoutput {"weather"} = $weathers {$mythoutput {"weather"}}; }

    else  { };




  #icon mappings to be made
             my %icons = ("01","sunny.png",
			  "02","sunny.png",
	   		  "03","sunny.png",
	 		  "04","pcloudy.png",
	 		  "05","pcloudy.png",
			  "06","mcloudy.png",
			  "07","mcloudy.png",
			  "08","cloudy.png",
			  "11","fog.png",
			  "12","lshowers.png",
			  "13","lshowers.png",
			  "14","showers.png",
			  "15","thunshowers.png",
			  "16","thunshowers.png",
			  "17","thunshowers.png",
			  "18","showers.png",
			  "19","snowshow.png",
			  "20","snowshow.png",
			  "21","sunny.png",
			  "22","snowshow.png",
			  "23","snowshow.png",
			  "24","snowshow.png",
			  "25","lshowers.png",
			  "26","lshowers.png",
			  "27","unknown.png",
			  "28","unknown.png",
			  "29","rainsnow.png",
			  "30","sunny.png",
			  "31","snowshow.png",
			  "32","unknown.png",
			  "33","fair.png",
			  "34","fair.png",
			  "35","fair.png",
			  "36","fair.png",
			  "37","fair.png",
			  "38","fair.png",
			  "39","lshowers.png",
			  "40","lshowers.png",
			  "41","thunshowers.png",
			  "43","lshowers.png",
			  "44","flurries.png",
			  "45","flurries.png",
			  "45","unknown.png",
			  "46","fair.png");

	# conversions icon/ mapping
		if ( exists $icons { $mythoutput {"weather_icon"}}) {
			$mythoutput {"weather_icon"} = $icons {$mythoutput {"weather_icon"}}; }
		else { $mythoutput {"weather_icon"} = "unknown.png" ; }
			$mythoutput {"relative_humidity"} =~ s/%// ;

	# conversions m/s en km/h for the windspeed
		$mythoutput {"windgust"} = $mythoutput {"wind_gust"}*3.60 ;
		$mythoutput {"windspdgst"} = $mythoutput {"wind_spdgst"}*3.60 ;
		$mythoutput {"wind_gust"} = $mythoutput {"windgust"} ;
		$mythoutput {"wind_spdgst"} = $mythoutput {"windspdgst"} ;
		$mythoutput {"wind_spdgst"} .= " (" . $mythoutput {"wind_gust"} . ")" ;


	# download forecast 3/6 days
		my $i;
		for ($i = 0; $i < 6; ++$i) {

			$mythoutput{"date-" . $i} = $xml->{forecast}->{day}->[$i]->{daycode} ;
			$mythoutput{"icon-" . $i} = $xml->{forecast}->{day}->[$i]->{daytime}->{weathericon} ;
			$mythoutput{"low-" . $i} = $xml->{forecast}->{day}->[$i]->{daytime}->{lowtemperature} ;
			$mythoutput{"high-" . $i} = $xml->{forecast}->{day}->[$i]->{daytime}->{hightemperature} ;

			if ( exists $daycodes { $mythoutput {"date-" . $i}}) {
				$mythoutput {"date-" . $i} = $daycodes {$mythoutput {"date-" . $i}}; }
			else { $mythoutput {"date-" . $i} = "Inconnu" ; }


			if ( exists $icons { $mythoutput {"icon-" . $i}}) {
				$mythoutput {"icon-" . $i} = $icons {$mythoutput {"icon-" . $i}}; }
			else { $mythoutput {"icon-" . $i} = "unknown.png" ; }
		}


	#output the data

		foreach $keyword (@types)
		{ $value = $mythoutput{$keyword}; 
		if (ref($value) eq 'HASH'){
			printf "%s::%s\n",$keyword,$value->{content};
		}
		else {
		printf "%s::%s\n",$keyword,$value;
		}
}
