diary-header
v0.1.12
Published
A command-line tool that generates a Markdown header for daily diary entries with location, astronomical, and weather information
Maintainers
Readme
diary-header
A command-line tool written in Rust that interactively generates a Markdown header for your daily diary entries. It automatically retrieves geolocation data, calculates sunrise/sunset times, and determines the sexagenary cycle (干支 - Eto) for any given date.
Features
- Interactive Prompts: Easily select the date and location using an interactive terminal UI.
- Location Auto-Detection: Automatically fetches your current location, latitude, longitude, and timezone based on your IP address.
- Manual Location Selection: Optionally select from a comprehensive list of cities worldwide if you are writing a diary for somewhere else.
- Astronomical Calculations: Calculates precise sunrise and sunset times based on the selected date and location coordinates.
- Weather Information: Retrieves daily maximum and minimum temperatures for the selected date and location.
- Sexagenary Cycle (干支): Automatically computes the traditional continuous calendar cycle (Eto) for the given date.
- Six-Day Cycle (六曜): Calculates the traditional Japanese six-day cycle (Rokuyo) for fortune-telling and event planning.
- Language Configuration: Choose between Japanese (ja) and English (en) for the output format.
- Customizable Display Order: Configure which information to display and in what order via the config file.
- Persistent Configuration: Prompts for an initial configuration (language) and saves it to a configuration file (
~/.config/diary-header/config.toml). You can update this later using theconfigsubcommand.
Installation
Via npm (Recommended)
The easiest way to install diary-header is via npm:
npm install -g diary-headerThis will download a prebuilt binary for your platform and make the diary-header command available globally.
Via Cargo
Alternatively, if you have Rust and Cargo installed, you can install from source:
git clone https://github.com/massn/diary-header.git
cd diary-header
cargo install --path .Or just run it directly:
cargo runUsage
When you run diary-header (or cargo run), the tool will interactively prompt you for the necessary information:
- First-time Setup: If the configuration file does not exist, it will ask for your preferred output language (Japanese or English). This is saved to
~/.config/diary-header/config.toml. - Date Selection: Prompts you to select a date for the diary header (defaults to today).
- Location Selection: Prompts you to choose "Current Location (Auto via IP)" or select a specific city from the list.
Example Output
Once the selections are made, the tool outputs a localized Markdown header depending on your configured language:
Japanese Output (ja):
## 2024-11-20 (水)
- 場所 (Current IP Address): Tokyo (Tokyo)
- 緯度経度: (35.6895, 139.6917)
- タイムゾーン: Asia/Tokyo
- 日の出: 06:21:43 JST+0900
- 日の入り: 16:32:11 JST+0900
- 天気: 晴れ
- 降水確率: 20%
- 気温: 最高 18.5°C / 最低 12.3°C
- 干支: 甲辰
- 六曜: 先勝English Output (en):
## 2024-11-20 (Wednesday)
- Location (Current IP Address): Tokyo (Tokyo)
- Lat/Lon: (35.6895, 139.6917)
- Timezone: Asia/Tokyo
- Sunrise: 06:21:43 JST+0900
- Sunset: 16:32:11 JST+0900
- Weather: Mainly clear
- Precipitation Probability: 20%
- Temperature: Max 18.5°C / Min 12.3°C
- Sexagenary Cycle: 甲辰
- Rokuyo: 先勝You can redirect this output directly to your diary file or copy it securely:
diary-header >> my-diary.mdConfiguration
The configuration file is stored in ~/.config/diary-header/config.toml (macOS/Linux) or %APPDATA%\diary-header\config.toml (Windows).
Language Setting
You can interactively change the language setting at any time by using the config subcommand:
diary-header config
# Or with cargo:
cargo run -- configDisplay Order Customization
You can customize the order of displayed information by manually editing the configuration file. By default, all items are displayed in the following order:
language = "en"
display_order = [
"location",
"coordinates",
"timezone",
"sunrise",
"sunset",
"weather",
"precipitation",
"temperature",
"sexagenary_cycle",
"rokuyo",
]Available items:
location- Location information (city/region)coordinates- Latitude and longitudetimezone- Timezonesunrise- Sunrise timesunset- Sunset timeweather- Weather conditionprecipitation- Precipitation probabilitytemperature- Max/min temperaturesexagenary_cycle- Sexagenary cycle (干支)rokuyo- Six-day cycle (六曜)
You can reorder these items or remove items you don't need. For example, to show only weather-related information:
language = "ja"
display_order = [
"weather",
"temperature",
"precipitation",
]Items not included in display_order will not be displayed in the output.
Dependencies
- inquire: For interactive terminal prompts (date, select, text).
- reqwest: For hitting the
ip-api.comendpoint to fetch IP-based timezone and geolocation info, and the Open-Meteo API for weather data. - sunrise: For calculating the exact sunrise and sunset times.
- tzf-rs: For fast offline timezone timezone lookups based on longitude and latitude.
- chrono: For date and time manipulation.
- cities: For the embedded list of global cities.
- clap: For CLI argument parsing and subcommands.
- serde / serde_json / toml: For data serialization and writing/reading the config.
Development
Release Process
The version is managed through package.json, which serves as the single source of truth. The build.rs script automatically reads the version from package.json during compilation.
To create a new release:
Update the version in
package.json:# Edit package.json and update the version field # Example: "version": "0.1.9"Update
Cargo.tomlversion (optional but recommended):# Keep Cargo.toml in sync to avoid confusion # Example: version = "0.1.9"Update
Cargo.lock:cargo update -p diary-headerBuild and verify the version:
cargo build --release ./target/release/diary-header --version # Should output: diary-header 0.1.9Commit the changes:
git add package.json Cargo.toml Cargo.lock git commit -m "chore: bump version to 0.1.9"Create a git tag:
git tag -a v0.1.9 -m "Release v0.1.9"Push to remote:
git push origin main git push origin v0.1.9Publish to npm:
npm publish
Note: The version displayed by --version comes from package.json, not from git tags. This ensures consistent versioning across npm packages and the binary.
License
This project is licensed under the MIT License. See the LICENSE file for details.
