iTranslated by AI
Fetching the Latest Calendar Information from the National Astronomical Observatory of Japan [Sponsored Post]
To an amateur's eye, it might seem like the National Diet does nothing but engage in endless trivialities, but it appears they've managed to change next year's calendar before anyone noticed.
The National Astronomical Observatory of Japan (NAOJ) website also states:
Specifically, according to Act No. 68 of December 4, Reiwa 2 "Act for Partial Revision of the Act on Special Measures for the Tokyo Olympic and Paralympic Games of 2020, etc.", for the year Reiwa 3 only, Marine Day will be July 22 (the day before the Tokyo Olympics opening ceremony), Sports Day will be July 23 (the day of the opening ceremony), and Mountain Day will be August 8 (the day of the closing ceremony). Furthermore, since August 8 falls on a Sunday, the following day, August 9, will be a holiday.
It seems they have already updated their information.
Since NAOJ publishes calendar information via Google Calendar, you can use this data to retrieve the latest calendar.
Actually, to kill time while I was unemployed, I created and released a Go package to retrieve this calendar information from NAOJ.
To get the holidays, you can do it like this:
package main
import (
"fmt"
"os"
"github.com/spiegel-im-spiegel/koyomi"
)
func main() {
start, _ := koyomi.DateFrom("2021-01-01")
end, _ := koyomi.DateFrom("2021-12-31")
k, err := koyomi.NewSource(
koyomi.WithCalendarID(koyomi.Holiday),
koyomi.WithStartDate(start),
koyomi.WithEndDate(end),
).Get()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
fmt.Println("| Date | Description |")
fmt.Println("| ---- | ---- |")
for _, e := range k.Events() {
fmt.Printf("| %v | %v |\n", e.Date, e.Title)
}
}
Then you can get the result as follows:
$ go run sample.go
| Date | Description |
| ---- | ---- |
| 2021-01-01 | New Year's Day |
| 2021-01-11 | Coming of Age Day |
| 2021-02-11 | Foundation Day |
| 2021-02-23 | Emperor's Birthday |
| 2021-03-20 | Vernal Equinox Day |
| 2021-04-29 | Showa Day |
| 2021-05-03 | Constitution Memorial Day |
| 2021-05-04 | Greenery Day |
| 2021-05-05 | Children's Day |
| 2021-07-22 | Marine Day |
| 2021-07-23 | Sports Day |
| 2021-08-08 | Mountain Day |
| 2021-08-09 | Holiday |
| 2021-09-20 | Respect for the Aged Day |
| 2021-09-23 | Autumnal Equinox Day |
| 2021-11-03 | Culture Day |
| 2021-11-23 | Labour Thanksgiving Day |
The koyomi.Koyomi struct, which is the return value of the koyomi.NewSource( ... ).Get() method above, has methods for converting to CSV and JSON formats. For example, it can be output like this:
bytesData, err := k.EncodeCSV()
By the way, it's incredibly slow because it fetches the entire iCal data from Google Calendar. Usually, it's better to use it in a batch process and store the data in a database or somewhere else.
...I can almost hear the screams of those in administration and general affairs. My condolences...
Discussion