From 19582dd139760899ca3d45beb5443fe94cc1ab37 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 10 Apr 2011 15:37:30 -0400 Subject: [PATCH] Holidays - Renamed all holiday files to include a locale, rather than just a country code. - Enhanced update-holidays.pl add-on script to support regions, provide better error handling, error on missing Perl module, warnings on unavailable data, and help text. - Updated documentation accordingly. --- ChangeLog | 2 + NEWS | 4 +- doc/man/task-tutorial.5.in | 5 +- doc/man/taskrc.5.in | 11 +-- doc/rc/{holidays-BY.rc => holidays.be-BY.rc} | 0 doc/rc/{holidays-CZ.rc => holidays.cs-CZ.rc} | 0 doc/rc/{holidays-DK.rc => holidays.da-DK.rc} | 0 doc/rc/{holidays-AT.rc => holidays.de-AT.rc} | 0 doc/rc/{holidays-DE.rc => holidays.de-DE.rc} | 0 doc/rc/{holidays-CA.rc => holidays.en-CA.rc} | 0 doc/rc/{holidays-UK.rc => holidays.en-GB.rc} | 0 doc/rc/{holidays-NZ.rc => holidays.en-NZ.rc} | 0 doc/rc/{holidays-US.rc => holidays.en-US.rc} | 0 doc/rc/{holidays-ES.rc => holidays.es-ES.rc} | 0 doc/rc/{holidays-FR.rc => holidays.fr-FR.rc} | 0 doc/rc/{holidays-IT.rc => holidays.it-IT.rc} | 0 doc/rc/{holidays-NO.rc => holidays.nb-NO.rc} | 0 doc/rc/{holidays-NL.rc => holidays.nl-NL.rc} | 0 doc/rc/{holidays-SE.rc => holidays.sv-SE.rc} | 0 scripts/add-ons/update-holidays.pl | 85 +++++++++++++++++--- 20 files changed, 86 insertions(+), 21 deletions(-) rename doc/rc/{holidays-BY.rc => holidays.be-BY.rc} (100%) rename doc/rc/{holidays-CZ.rc => holidays.cs-CZ.rc} (100%) rename doc/rc/{holidays-DK.rc => holidays.da-DK.rc} (100%) rename doc/rc/{holidays-AT.rc => holidays.de-AT.rc} (100%) rename doc/rc/{holidays-DE.rc => holidays.de-DE.rc} (100%) rename doc/rc/{holidays-CA.rc => holidays.en-CA.rc} (100%) rename doc/rc/{holidays-UK.rc => holidays.en-GB.rc} (100%) rename doc/rc/{holidays-NZ.rc => holidays.en-NZ.rc} (100%) rename doc/rc/{holidays-US.rc => holidays.en-US.rc} (100%) rename doc/rc/{holidays-ES.rc => holidays.es-ES.rc} (100%) rename doc/rc/{holidays-FR.rc => holidays.fr-FR.rc} (100%) rename doc/rc/{holidays-IT.rc => holidays.it-IT.rc} (100%) rename doc/rc/{holidays-NO.rc => holidays.nb-NO.rc} (100%) rename doc/rc/{holidays-NL.rc => holidays.nl-NL.rc} (100%) rename doc/rc/{holidays-SE.rc => holidays.sv-SE.rc} (100%) diff --git a/ChangeLog b/ChangeLog index b6d6fc002..5139456b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ + The old 'curses' configuration variable is now replaced by 'detection', and has the same meaning - whether or not to auto-detect terminal size. + Added Czech Republic holiday files (thanks to Tomas Cech). + + All holiday files have been renamed to include a locale, rather than just a + country code. For example: holidays.en-US.rc. # Tracked Features, sorted by ID. + Added feature #700, which adds tab-completion of built-in tags. diff --git a/NEWS b/NEWS index 162bfc404..ba7f02473 100644 --- a/NEWS +++ b/NEWS @@ -17,7 +17,9 @@ New commands in taskwarrior 2.0.0 New configuration options in taskwarrior 2.0.0 - - Now includes Belarus and Czech Republic holiday data. + - Now includes Belarus and Czech Republic holiday data. Please note that + the holiday file names now include a full locale. For example: + 'holidays.en-US.rc' instead of 'holidays-US.rc'. - The old 'curses' configuration variable is renamed to 'detection', but retains the original meaning, which is whether or not to auto-detect the dimensions of the terminal window. diff --git a/doc/man/task-tutorial.5.in b/doc/man/task-tutorial.5.in index 8fa79e0f4..968314497 100644 --- a/doc/man/task-tutorial.5.in +++ b/doc/man/task-tutorial.5.in @@ -1621,7 +1621,7 @@ used most. You can create your own, or use one of the samples to show holidays on the calendar. Try adding this line to your ~/.taskrc file: .RS -include /usr/local/share/doc/task/rc/holidays-US.rc +include /usr/local/share/doc/task/rc/holidays.en-US.rc .RE Then: @@ -1654,7 +1654,8 @@ $ task calendar Legend: today, due, due-today, overdue, weekend, holiday, weeknumber. .RE -There are holiday files for CA, DE, ES, FR, NL, SE, UK and US. +There are holiday files for be-BY, cs-CZ, da-DK, de-AT, de-DE, en-CA, en-GB, +en-NZ, en-US, es-ES, fr-FR, it-IT, nb-NO, nl-NL and sv-SE locales. You can see the whole year, see due tasks as well, and see the holidays: diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index e4caa4918..6cfc47c8d 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -115,7 +115,7 @@ ones containing just the relevant configuration data like colors, etc. There are two excellent uses of includes in your .taskrc, shown here: .RS -include /usr/local/share/doc/task/rc/holidays-US.rc +include /usr/local/share/doc/task/rc/holidays.en-US.rc .br include /usr/local/share/doc/task/rc/dark-16.theme .RE @@ -183,13 +183,6 @@ help text. .SS MISCELLANEOUS -.TP -.B locale=en-US -The locale is a combination of ISO 639-1 language code and ISO 3166 country -code. If not specified, will assume en-US. If specified, taskwarrior will -locate the correct file of localized strings and proceed. It is an error to -specify a locale for which there is no strings file. - .TP .B verbose=yes Controls some of the verbosity of taskwarrior. @@ -562,7 +555,7 @@ be included like this: .RS .RS .br -include /usr/local/share/doc/task/rc/holidays-US.rc +include /usr/local/share/doc/task/rc/holidays.en-US.rc .RE .RE diff --git a/doc/rc/holidays-BY.rc b/doc/rc/holidays.be-BY.rc similarity index 100% rename from doc/rc/holidays-BY.rc rename to doc/rc/holidays.be-BY.rc diff --git a/doc/rc/holidays-CZ.rc b/doc/rc/holidays.cs-CZ.rc similarity index 100% rename from doc/rc/holidays-CZ.rc rename to doc/rc/holidays.cs-CZ.rc diff --git a/doc/rc/holidays-DK.rc b/doc/rc/holidays.da-DK.rc similarity index 100% rename from doc/rc/holidays-DK.rc rename to doc/rc/holidays.da-DK.rc diff --git a/doc/rc/holidays-AT.rc b/doc/rc/holidays.de-AT.rc similarity index 100% rename from doc/rc/holidays-AT.rc rename to doc/rc/holidays.de-AT.rc diff --git a/doc/rc/holidays-DE.rc b/doc/rc/holidays.de-DE.rc similarity index 100% rename from doc/rc/holidays-DE.rc rename to doc/rc/holidays.de-DE.rc diff --git a/doc/rc/holidays-CA.rc b/doc/rc/holidays.en-CA.rc similarity index 100% rename from doc/rc/holidays-CA.rc rename to doc/rc/holidays.en-CA.rc diff --git a/doc/rc/holidays-UK.rc b/doc/rc/holidays.en-GB.rc similarity index 100% rename from doc/rc/holidays-UK.rc rename to doc/rc/holidays.en-GB.rc diff --git a/doc/rc/holidays-NZ.rc b/doc/rc/holidays.en-NZ.rc similarity index 100% rename from doc/rc/holidays-NZ.rc rename to doc/rc/holidays.en-NZ.rc diff --git a/doc/rc/holidays-US.rc b/doc/rc/holidays.en-US.rc similarity index 100% rename from doc/rc/holidays-US.rc rename to doc/rc/holidays.en-US.rc diff --git a/doc/rc/holidays-ES.rc b/doc/rc/holidays.es-ES.rc similarity index 100% rename from doc/rc/holidays-ES.rc rename to doc/rc/holidays.es-ES.rc diff --git a/doc/rc/holidays-FR.rc b/doc/rc/holidays.fr-FR.rc similarity index 100% rename from doc/rc/holidays-FR.rc rename to doc/rc/holidays.fr-FR.rc diff --git a/doc/rc/holidays-IT.rc b/doc/rc/holidays.it-IT.rc similarity index 100% rename from doc/rc/holidays-IT.rc rename to doc/rc/holidays.it-IT.rc diff --git a/doc/rc/holidays-NO.rc b/doc/rc/holidays.nb-NO.rc similarity index 100% rename from doc/rc/holidays-NO.rc rename to doc/rc/holidays.nb-NO.rc diff --git a/doc/rc/holidays-NL.rc b/doc/rc/holidays.nl-NL.rc similarity index 100% rename from doc/rc/holidays-NL.rc rename to doc/rc/holidays.nl-NL.rc diff --git a/doc/rc/holidays-SE.rc b/doc/rc/holidays.sv-SE.rc similarity index 100% rename from doc/rc/holidays-SE.rc rename to doc/rc/holidays.sv-SE.rc diff --git a/scripts/add-ons/update-holidays.pl b/scripts/add-ons/update-holidays.pl index 3ed10e5a1..675fa2df6 100755 --- a/scripts/add-ons/update-holidays.pl +++ b/scripts/add-ons/update-holidays.pl @@ -29,8 +29,21 @@ use strict; use warnings; use Getopt::Long; -use JSON; -use LWP::Simple; + +# Give a nice error if the (non-standard) JSON module is not installed. +eval "use JSON"; +if ($@) +{ + print "Error: You need to install the JSON Perl module.\n"; + exit 1; +} + +eval "use LWP::Simple"; +if ($@) +{ + print "Error: You need to install the LWP::Simple Perl module.\n"; + exit 1; +} # Command line options, argument validation. my $help; @@ -58,6 +71,33 @@ usage: update-holidays.pl [--help] --file Location of the holiday file to update. Note: this file *will* be overwritten. +Typical usage is to simply specify a locale, like this: + + ./update-holidays.pl --locale en-US --file holidays.en-US.rc + +This will give you all holidays for the locale. If you want data for a locale +that has regional data, you may want to specify regions, to make sure you get +the data local to your region. For example, the following command will download +Australian holiday data that is either national, or specific to the New South +Wales territory. + + update-holidays.pl --locale en-AU \ + --region NSW \ + --file holidays.en-AU.rc + +Multiple regions may be specified, such as the two Swiss cantons of Zürich and +Schwyz: + + update-holidays.pl --locale de-CH \ + --region Zürich \ + --region Schwyz \ + --file holidays.de-CH.rc + +See http://holidata.net for details of supported locales and regions. + +It is recommended that you regularly update your holiday files. Not only does +this keep your holiday data current, but allows for corrected data to be used. + EOF exit 1; @@ -66,6 +106,9 @@ EOF # File name is required. die "You must specify a holiday file to update.\n" if ! $file; +# Convert @regions to %region_hash to simplify lookup. +my %region_hash = map {$_ => undef} @regions; + # Perhaps the locale can be found in the file name, if not already specified? if (!$locale && $file =~ /([a-z]{2}-[A-Z]{2})/) @@ -84,11 +127,29 @@ my $next = $current + 1; my $url_current = "http://holidata.net/${locale}/${current}.json"; my $url_next = "http://holidata.net/${locale}/${next}.json"; -# Fetch the data. +# Fetch data for the current year. +my $data_current = get ($url_current); +print "\n", + "Data for ${locale}, for ${current} could not be downloaded. This could\n", + "mean that you do not have an internet connection, or that\n", + "Holidata.net does not support this locale and/or year.\n", + "\n" + unless defined $data_current; + +# Fetch data for the next year. +my $data_next = get ($url_next); +print "\n", + "Data for ${locale}, for ${next} could not be downloaded. This could\n", + "mean that you do not have an internet connection, or that\n", + "Holidata.net does not support this locale and/or year.\n", + "\n" + unless defined $data_next; + +# Without data, cannot proceed. my $data; -eval {$data = get ($url_current);}; -eval {$data .= get ($url_next);}; -die "Could not query data for ${locale}, for ${next}.\n" unless defined $data; +$data .= $data_current if defined $data_current; +$data .= $data_next if defined $data_next; +exit (1) if !defined $data || $data eq ''; # Filter the holidays according to @regions. my $id = 1; @@ -97,14 +158,20 @@ for my $holiday (split /\n/ms, $data) { my $parsed = from_json ($holiday); - $content .= "holiday.${locale}${id}.name=" . $parsed->{'description'} . "\n" . - "holiday.${locale}${id}.date=" . $parsed->{'date'} . "\n"; + if (@regions == 0 || + (@regions > 0 && ($parsed->{'region'} eq '' || + exists $region_hash{$parsed->{'region'}}))) + { + $content .= "holiday.${locale}${id}.name=" . $parsed->{'description'} . "\n" . + "holiday.${locale}${id}.date=" . $parsed->{'date'} . "\n"; + } ++$id; } # Overwrite the file. -if (open my $fh, '>:encoding(UTF-8)', $file) +if (open my $fh, '>', $file) +#if (open my $fh, '>:encoding(UTF-8)', $file) { print $fh "# International Holiday Data provided by Holidata.net\n",