mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
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.
This commit is contained in:
parent
40b2258589
commit
19582dd139
20 changed files with 86 additions and 21 deletions
|
@ -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.
|
||||
|
|
4
NEWS
4
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.
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue