Initial commit

This commit is contained in:
Zoé Cassiopée Gauthier 2024-11-01 17:30:04 -04:00
commit ada1e96cf8
9 changed files with 171 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__
dist

9
LICENSE.txt Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024-present Zoé Cassiopée Gauthier <hello@blorp.dev>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# Phase Of The Moon
[![PyPI - Version](https://img.shields.io/pypi/v/phase-of-the-moon.svg)](https://pypi.org/project/phase-of-the-moon)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/phase-of-the-moon.svg)](https://pypi.org/project/phase-of-the-moon)
Displays a message either during a full moon or during a new moon. The calculation is based on the Nethack `phase_of_the_moon` function.
-----
## Table of Contents
- [Installation](#installation)
- [License](#license)
## Installation
```console
pip install phase-of-the-moon
```
## License
`phase-of-the-moon` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

62
pyproject.toml Normal file
View File

@ -0,0 +1,62 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "phase-of-the-moon"
dynamic = ["version"]
description = 'Displays a message depending on the current phase of the moon.'
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
keywords = []
authors = [
{ name = "Zoé Cassiopée Gauthier", email = "zoe.gauthier@blorp.dev" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []
[project.urls]
Source = "https://git.blorp.dev/zo/phase-of-the-moon"
[project.scripts]
nh-phase-of-the-moon = "phase_of_the_moon:main"
[tool.hatch.version]
path = "src/phase_of_the_moon/__about__.py"
[tool.hatch.envs.types]
extra-dependencies = [
"mypy>=1.0.0",
]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/phase_of_the_moon tests}"
[tool.coverage.run]
source_pkgs = ["phase_of_the_moon", "tests"]
branch = true
parallel = true
omit = [
"src/phase_of_the_moon/__about__.py",
]
[tool.coverage.paths]
phase_of_the_moon = ["src/phase_of_the_moon", "*/phase-of-the-moon/src/phase_of_the_moon"]
tests = ["tests", "*/phase-of-the-moon/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

View File

@ -0,0 +1,7 @@
# Copyright 2024 Zoé Cassiopée Gauthier.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
__version__ = "0.0.1"

View File

@ -0,0 +1,9 @@
# Copyright 2024 Zoé Cassiopée Gauthier.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
from phase_of_the_moon.main import main
__all__ = ["main"]

View File

@ -0,0 +1,30 @@
# Copyright 2024 Zoé Cassiopée Gauthier.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import datetime as dt
NEW_MOON = 0
FULL_MOON = 4
def phase_of_the_moon(local_time: dt.datetime) -> int:
tt = local_time.timetuple()
day_of_year = tt.tm_yday
golden_number = (tt.tm_year % 19) + 1
epact = (11 * golden_number + 18) % 30
if (epact == 25 and golden_number > 11) or epact == 24:
epact += 1
return (((((day_of_year + epact) * 6) + 11) % 177) // 22) & 7
def main():
today = dt.datetime.now()
moon_phase = phase_of_the_moon(today)
if moon_phase == NEW_MOON:
print("Be careful! New moon tonight.")
elif moon_phase == FULL_MOON:
print("You are lucky! Full moon tonight.")

6
tests/__init__.py Normal file
View File

@ -0,0 +1,6 @@
# Copyright 2024 Zoé Cassiopée Gauthier.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

View File

@ -0,0 +1,23 @@
# Copyright 2024 Zoé Cassiopée Gauthier.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import datetime as dt
from phase_of_the_moon.main import phase_of_the_moon, NEW_MOON, FULL_MOON
def test_new_moon():
local_time = dt.datetime(1996, 9, 13)
assert phase_of_the_moon(local_time) == NEW_MOON
def test_full_moon():
local_time = dt.datetime(1998, 3, 13)
assert phase_of_the_moon(local_time) == FULL_MOON
def test_any_other_moon_phase():
local_time = dt.datetime(2000, 1, 1)
moon_phase = phase_of_the_moon(local_time)
assert moon_phase != FULL_MOON
assert moon_phase != NEW_MOON