A Python script to calculate and display the Heavenly Stem (Jikkan) and Earthly Branch (Eto/Junishi) for a given date.
Project description
Tiger and Dragon (Stem/Branch Calculator)
A Python script to calculate and display the Heavenly Stem (Jikkan) and Earthly Branch (Eto/Junishi) for a given date.
Features
- Calculates the Stem/Branch combination for a given year.
- Calculates the Stem/Branch combination for a given day.
- Supports output in Japanese (Kanji), English, or Emoji.
- Allows custom output formatting using template strings.
Installation
-
Clone the repository.
-
Install dependencies using uv (
pytestis required for running tests).uv sync --dev
Usage
Run the script from the command line:
python main.py [options]
Options
--lang {kanji,english,emoji}: Specify the output language. Default iskanji. (Ignored if--formatis used)kanji: Display in Japanese Kanji (e.g., 甲子)english: Display in English (e.g., Wood Yang / Rat)emoji: Display using emojis (e.g., 🌳🌞/🐀)
--format FORMAT_STRING: Specify a custom output format using a template string. This option overrides--lang. Available variables:{year_stem_kanji},{year_stem_english},{year_stem_emoji}{year_branch_kanji},{year_branch_english},{year_branch_emoji}{day_stem_kanji},{day_stem_english},{day_stem_emoji}{day_branch_kanji},{day_branch_english},{day_branch_emoji}{date_kanji},{date_english}
Examples
- Display in default language (Kanji):
python main.py - Display in English:
python main.py --lang english
- Display using emojis:
python main.py --lang emoji
- Display using a custom format:
python main.py --format "Date: {date_english}, Year: {year_stem_english}/{year_branch_english} ({year_stem_emoji}/{year_branch_emoji}), Day: {day_stem_english}/{day_branch_english} ({day_stem_emoji}/{day_branch_emoji})"
# Example with Japanese date and combined emoji/kanji python main.py --format "Date (Kanji): {date_kanji}, Day Stem/Branch: {day_stem_emoji}{day_branch_emoji} ({day_stem_kanji}{day_branch_kanji})"
Using as a Library
You can import functions from main.py into other Python scripts.
# example.py
import datetime
from main import stem_from_day, branch_from_day, Stem, Branch, Language
target_date = datetime.date(2024, 12, 25)
# Get the day's Stem
day_stem = stem_from_day(target_date)
# Get the day's Branch
day_branch = branch_from_day(target_date)
print(f"Date: {target_date}")
print(f"Day Stem (Kanji): {day_stem.display(Language.KANJI)}")
print(f"Day Branch (English): {day_branch.display(Language.ENGLISH)}")
print(f"Day Stem/Branch (Emoji): {day_stem.display_emoji()}/{day_branch.display_emoji()}")
Testing
Run tests using pytest.
uv run pytest -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tiger_and_dragon-0.1.1.tar.gz.
File metadata
- Download URL: tiger_and_dragon-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbe6f14d1fe434e839cb08474d4005603b93c09e97ffc370f104089277da781c
|
|
| MD5 |
70ed0074c480a50795ec16b323831191
|
|
| BLAKE2b-256 |
6ebd47dc08bc65e38a58480550dd7b2f3da47cd2f1b3de96853d0d149e262c47
|
File details
Details for the file tiger_and_dragon-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tiger_and_dragon-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78767bbdf3751316e7c148568f21e33c4fdd833c9c7af42d23005c24977393d3
|
|
| MD5 |
824f221f9ae511fd3335263bbcc795c9
|
|
| BLAKE2b-256 |
e24eb69e88ab64f372d229f062b32ecdd0ac58068a93ec065e461391d3dc731a
|