tsukimoji 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tsukimoji-0.1.1/LICENSE +21 -0
- tsukimoji-0.1.1/PKG-INFO +62 -0
- tsukimoji-0.1.1/README.md +44 -0
- tsukimoji-0.1.1/pyproject.toml +26 -0
- tsukimoji-0.1.1/setup.cfg +4 -0
- tsukimoji-0.1.1/src/tsukimoji/__init__.py +88 -0
- tsukimoji-0.1.1/src/tsukimoji.egg-info/PKG-INFO +62 -0
- tsukimoji-0.1.1/src/tsukimoji.egg-info/SOURCES.txt +9 -0
- tsukimoji-0.1.1/src/tsukimoji.egg-info/dependency_links.txt +1 -0
- tsukimoji-0.1.1/src/tsukimoji.egg-info/top_level.txt +1 -0
- tsukimoji-0.1.1/tests/test_tsukimoji.py +80 -0
tsukimoji-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sam Lehman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tsukimoji-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tsukimoji
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Moon phase emoji for any date
|
|
5
|
+
Author-email: Sam Lehman <grieve@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/samlehman/tsukimoji
|
|
8
|
+
Keywords: moon,moon-phase,emoji,lunar,astronomy
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# tsukiMOJi
|
|
20
|
+
|
|
21
|
+
Moon phase emoji for any date. ζ (tsuki, "moon") + moji, as in emoji.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from tsukimoji import get_moon_phase, emoji
|
|
25
|
+
|
|
26
|
+
phase = get_moon_phase()
|
|
27
|
+
phase.emoji # "π"
|
|
28
|
+
phase.name # "Waxing Gibbous"
|
|
29
|
+
phase.age_days # 12.3
|
|
30
|
+
phase.illumination # 0.87
|
|
31
|
+
|
|
32
|
+
emoji() # just the emoji, for "now"
|
|
33
|
+
|
|
34
|
+
from datetime import datetime, timezone
|
|
35
|
+
get_moon_phase(datetime(2026, 1, 1, tzinfo=timezone.utc)) # phase for any specific time
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pip install tsukimoji
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## How it works
|
|
45
|
+
|
|
46
|
+
tsukiMOJi measures elapsed time since a known new moon (2000-01-06
|
|
47
|
+
18:14 UTC) against the synodic month (29.530588853 days) to find how far
|
|
48
|
+
into the current lunar cycle a given moment falls, then maps that
|
|
49
|
+
fraction onto the eight standard moon-phase emoji (ππππππππ).
|
|
50
|
+
Illumination is derived separately from the same cycle position via a
|
|
51
|
+
cosine curve, for display purposes.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
<p align="center">
|
|
60
|
+
<img src="https://raw.githubusercontent.com/samlehman/tsukimoji/main/made-in-baltimore.png" alt="Made in Baltimore" width="88" align="middle">
|
|
61
|
+
β <a href="https://paypal.me/samlehman">Buy me a coffee</a> Β· <a href="https://paypal.me/samlehman">γγΌγ²γΌγγγγ£γ¦</a>
|
|
62
|
+
</p>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# tsukiMOJi
|
|
2
|
+
|
|
3
|
+
Moon phase emoji for any date. ζ (tsuki, "moon") + moji, as in emoji.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from tsukimoji import get_moon_phase, emoji
|
|
7
|
+
|
|
8
|
+
phase = get_moon_phase()
|
|
9
|
+
phase.emoji # "π"
|
|
10
|
+
phase.name # "Waxing Gibbous"
|
|
11
|
+
phase.age_days # 12.3
|
|
12
|
+
phase.illumination # 0.87
|
|
13
|
+
|
|
14
|
+
emoji() # just the emoji, for "now"
|
|
15
|
+
|
|
16
|
+
from datetime import datetime, timezone
|
|
17
|
+
get_moon_phase(datetime(2026, 1, 1, tzinfo=timezone.utc)) # phase for any specific time
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
pip install tsukimoji
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## How it works
|
|
27
|
+
|
|
28
|
+
tsukiMOJi measures elapsed time since a known new moon (2000-01-06
|
|
29
|
+
18:14 UTC) against the synodic month (29.530588853 days) to find how far
|
|
30
|
+
into the current lunar cycle a given moment falls, then maps that
|
|
31
|
+
fraction onto the eight standard moon-phase emoji (ππππππππ).
|
|
32
|
+
Illumination is derived separately from the same cycle position via a
|
|
33
|
+
cosine curve, for display purposes.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<img src="https://raw.githubusercontent.com/samlehman/tsukimoji/main/made-in-baltimore.png" alt="Made in Baltimore" width="88" align="middle">
|
|
43
|
+
β <a href="https://paypal.me/samlehman">Buy me a coffee</a> Β· <a href="https://paypal.me/samlehman">γγΌγ²γΌγγγγ£γ¦</a>
|
|
44
|
+
</p>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tsukimoji"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Moon phase emoji for any date"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Sam Lehman", email = "grieve@gmail.com" }]
|
|
13
|
+
keywords = ["moon", "moon-phase", "emoji", "lunar", "astronomy"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/samlehman/tsukimoji"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""tsukiMOJi: moon phase emoji for any date.
|
|
2
|
+
|
|
3
|
+
(tsuki, "moon") + moji, as in emoji.
|
|
4
|
+
|
|
5
|
+
Ported from the original moon-phase.html JavaScript prototype.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from datetime import datetime, timedelta, timezone
|
|
13
|
+
from typing import Optional
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"SYNODIC_MONTH_DAYS",
|
|
17
|
+
"KNOWN_NEW_MOON",
|
|
18
|
+
"PHASES",
|
|
19
|
+
"MoonPhase",
|
|
20
|
+
"get_moon_phase",
|
|
21
|
+
"emoji",
|
|
22
|
+
"name",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.1"
|
|
26
|
+
|
|
27
|
+
SYNODIC_MONTH_DAYS = 29.530588853
|
|
28
|
+
_SYNODIC_MONTH_SECONDS = SYNODIC_MONTH_DAYS * 24 * 60 * 60
|
|
29
|
+
|
|
30
|
+
# A known new moon reference point: 2000-01-06 18:14 UTC.
|
|
31
|
+
KNOWN_NEW_MOON = datetime(2000, 1, 6, 18, 14, 0, tzinfo=timezone.utc)
|
|
32
|
+
|
|
33
|
+
PHASES = (
|
|
34
|
+
("\U0001F311", "New Moon"),
|
|
35
|
+
("\U0001F312", "Waxing Crescent"),
|
|
36
|
+
("\U0001F313", "First Quarter"),
|
|
37
|
+
("\U0001F314", "Waxing Gibbous"),
|
|
38
|
+
("\U0001F315", "Full Moon"),
|
|
39
|
+
("\U0001F316", "Waning Gibbous"),
|
|
40
|
+
("\U0001F317", "Last Quarter"),
|
|
41
|
+
("\U0001F318", "Waning Crescent"),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class MoonPhase:
|
|
47
|
+
emoji: str
|
|
48
|
+
name: str
|
|
49
|
+
age_days: float
|
|
50
|
+
illumination: float
|
|
51
|
+
|
|
52
|
+
def __str__(self) -> str: # pragma: no cover - trivial
|
|
53
|
+
return self.emoji
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_moon_phase(when: Optional[datetime] = None) -> MoonPhase:
|
|
57
|
+
"""Return the MoonPhase for ``when`` (defaults to now, UTC).
|
|
58
|
+
|
|
59
|
+
A naive ``datetime`` is treated as UTC.
|
|
60
|
+
"""
|
|
61
|
+
if when is None:
|
|
62
|
+
when = datetime.now(timezone.utc)
|
|
63
|
+
elif when.tzinfo is None:
|
|
64
|
+
when = when.replace(tzinfo=timezone.utc)
|
|
65
|
+
|
|
66
|
+
elapsed_seconds = (when - KNOWN_NEW_MOON) / timedelta(seconds=1)
|
|
67
|
+
cycles = elapsed_seconds / _SYNODIC_MONTH_SECONDS
|
|
68
|
+
age = ((cycles % 1) + 1) % 1
|
|
69
|
+
index = int((age + 1 / 16) * 8) % 8
|
|
70
|
+
illumination = (1 - math.cos(age * 2 * math.pi)) / 2
|
|
71
|
+
|
|
72
|
+
phase_emoji, phase_name = PHASES[index]
|
|
73
|
+
return MoonPhase(
|
|
74
|
+
emoji=phase_emoji,
|
|
75
|
+
name=phase_name,
|
|
76
|
+
age_days=age * SYNODIC_MONTH_DAYS,
|
|
77
|
+
illumination=illumination,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def emoji(when: Optional[datetime] = None) -> str:
|
|
82
|
+
"""Shortcut: just the emoji for ``when`` (defaults to now)."""
|
|
83
|
+
return get_moon_phase(when).emoji
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def name(when: Optional[datetime] = None) -> str:
|
|
87
|
+
"""Shortcut: just the phase name for ``when`` (defaults to now)."""
|
|
88
|
+
return get_moon_phase(when).name
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tsukimoji
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Moon phase emoji for any date
|
|
5
|
+
Author-email: Sam Lehman <grieve@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/samlehman/tsukimoji
|
|
8
|
+
Keywords: moon,moon-phase,emoji,lunar,astronomy
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# tsukiMOJi
|
|
20
|
+
|
|
21
|
+
Moon phase emoji for any date. ζ (tsuki, "moon") + moji, as in emoji.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from tsukimoji import get_moon_phase, emoji
|
|
25
|
+
|
|
26
|
+
phase = get_moon_phase()
|
|
27
|
+
phase.emoji # "π"
|
|
28
|
+
phase.name # "Waxing Gibbous"
|
|
29
|
+
phase.age_days # 12.3
|
|
30
|
+
phase.illumination # 0.87
|
|
31
|
+
|
|
32
|
+
emoji() # just the emoji, for "now"
|
|
33
|
+
|
|
34
|
+
from datetime import datetime, timezone
|
|
35
|
+
get_moon_phase(datetime(2026, 1, 1, tzinfo=timezone.utc)) # phase for any specific time
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pip install tsukimoji
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## How it works
|
|
45
|
+
|
|
46
|
+
tsukiMOJi measures elapsed time since a known new moon (2000-01-06
|
|
47
|
+
18:14 UTC) against the synodic month (29.530588853 days) to find how far
|
|
48
|
+
into the current lunar cycle a given moment falls, then maps that
|
|
49
|
+
fraction onto the eight standard moon-phase emoji (ππππππππ).
|
|
50
|
+
Illumination is derived separately from the same cycle position via a
|
|
51
|
+
cosine curve, for display purposes.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
<p align="center">
|
|
60
|
+
<img src="https://raw.githubusercontent.com/samlehman/tsukimoji/main/made-in-baltimore.png" alt="Made in Baltimore" width="88" align="middle">
|
|
61
|
+
β <a href="https://paypal.me/samlehman">Buy me a coffee</a> Β· <a href="https://paypal.me/samlehman">γγΌγ²γΌγγγγ£γ¦</a>
|
|
62
|
+
</p>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tsukimoji
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import unittest
|
|
4
|
+
from datetime import datetime, timedelta, timezone
|
|
5
|
+
|
|
6
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
|
7
|
+
|
|
8
|
+
from tsukimoji import ( # noqa: E402
|
|
9
|
+
KNOWN_NEW_MOON,
|
|
10
|
+
PHASES,
|
|
11
|
+
SYNODIC_MONTH_DAYS,
|
|
12
|
+
emoji,
|
|
13
|
+
get_moon_phase,
|
|
14
|
+
name,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestTsukimoji(unittest.TestCase):
|
|
19
|
+
def test_new_moon_instant(self):
|
|
20
|
+
phase = get_moon_phase(KNOWN_NEW_MOON)
|
|
21
|
+
self.assertEqual(phase.emoji, "\U0001F311")
|
|
22
|
+
self.assertEqual(phase.name, "New Moon")
|
|
23
|
+
self.assertLess(phase.illumination, 0.01)
|
|
24
|
+
|
|
25
|
+
def test_full_moon_half_cycle_later(self):
|
|
26
|
+
half_cycle_later = KNOWN_NEW_MOON + timedelta(days=SYNODIC_MONTH_DAYS / 2)
|
|
27
|
+
phase = get_moon_phase(half_cycle_later)
|
|
28
|
+
self.assertEqual(phase.emoji, "\U0001F315")
|
|
29
|
+
self.assertGreater(phase.illumination, 0.99)
|
|
30
|
+
|
|
31
|
+
def test_sample_is_known_phase(self):
|
|
32
|
+
sample = get_moon_phase(datetime(2026, 10, 1, 12, 0, tzinfo=timezone.utc))
|
|
33
|
+
known_emoji = {e for e, _ in PHASES}
|
|
34
|
+
self.assertIn(sample.emoji, known_emoji)
|
|
35
|
+
self.assertGreaterEqual(sample.age_days, 0)
|
|
36
|
+
self.assertLess(sample.age_days, 29.6)
|
|
37
|
+
|
|
38
|
+
def test_naive_datetime_treated_as_utc(self):
|
|
39
|
+
naive = datetime(2026, 10, 1, 12, 0)
|
|
40
|
+
aware = datetime(2026, 10, 1, 12, 0, tzinfo=timezone.utc)
|
|
41
|
+
self.assertEqual(get_moon_phase(naive), get_moon_phase(aware))
|
|
42
|
+
|
|
43
|
+
def test_shortcuts_match(self):
|
|
44
|
+
when = datetime(2026, 6, 15, tzinfo=timezone.utc)
|
|
45
|
+
phase = get_moon_phase(when)
|
|
46
|
+
self.assertEqual(emoji(when), phase.emoji)
|
|
47
|
+
self.assertEqual(name(when), phase.name)
|
|
48
|
+
|
|
49
|
+
def test_every_phase_at_its_exact_point(self):
|
|
50
|
+
# In this cycle, before 2000, and well after.
|
|
51
|
+
for cycle in (0, -3, 120):
|
|
52
|
+
for k, (expected_emoji, expected_name) in enumerate(PHASES):
|
|
53
|
+
with self.subTest(cycle=cycle, phase=expected_name):
|
|
54
|
+
phase = get_moon_phase(_at_cycle(cycle + k / 8))
|
|
55
|
+
self.assertEqual(phase.emoji, expected_emoji)
|
|
56
|
+
self.assertEqual(phase.name, expected_name)
|
|
57
|
+
|
|
58
|
+
def test_phase_boundaries(self):
|
|
59
|
+
# Each phase changes halfway between exact points, at (2k + 1)/16.
|
|
60
|
+
# The last boundary (15/16) wraps back round to New Moon.
|
|
61
|
+
hour = timedelta(hours=1)
|
|
62
|
+
for k, (_, before) in enumerate(PHASES):
|
|
63
|
+
after = PHASES[(k + 1) % 8][1]
|
|
64
|
+
boundary = (2 * k + 1) / 16
|
|
65
|
+
with self.subTest(boundary=f"{2 * k + 1}/16"):
|
|
66
|
+
self.assertEqual(get_moon_phase(_at_cycle(boundary) - hour).name, before)
|
|
67
|
+
self.assertEqual(get_moon_phase(_at_cycle(boundary) + hour).name, after)
|
|
68
|
+
|
|
69
|
+
def test_quarters_half_lit(self):
|
|
70
|
+
self.assertAlmostEqual(get_moon_phase(_at_cycle(2 / 8)).illumination, 0.5, places=3)
|
|
71
|
+
self.assertAlmostEqual(get_moon_phase(_at_cycle(6 / 8)).illumination, 0.5, places=3)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _at_cycle(cycles):
|
|
75
|
+
"""Moment at a given number of cycles (whole or fractional) from the reference."""
|
|
76
|
+
return KNOWN_NEW_MOON + timedelta(days=cycles * SYNODIC_MONTH_DAYS)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
unittest.main()
|