feat: Fix nutrition service and add location-based alerts
All checks were successful
continuous-integration/drone/push Build is passing

Changes:
- Fix nutrition service: add is_active column and Pydantic validation for UUID/datetime
- Add location-based alerts feature: users can now see alerts within 1km radius
- Fix CORS and response serialization in nutrition service
- Add getCurrentLocation() and loadAlertsNearby() functions
- Improve UI for nearby alerts display with distance and response count
This commit is contained in:
2025-12-13 16:34:50 +09:00
parent 3050e084fa
commit cfc93cb99a
34 changed files with 7016 additions and 17 deletions

View File

@@ -0,0 +1,150 @@
Metadata-Version: 2.4
Name: termcolor
Version: 3.2.0
Summary: ANSI color formatting for output in terminal
Project-URL: Changelog, https://github.com/termcolor/termcolor/releases
Project-URL: Homepage, https://github.com/termcolor/termcolor
Project-URL: Source, https://github.com/termcolor/termcolor
Author-email: Konstantin Lepa <konstantin.lepa@gmail.com>
Maintainer: Hugo van Kemenade
License-Expression: MIT
License-File: COPYING.txt
Keywords: ANSI,ANSI color,ANSI colour,color,colour,formatting,termcolor,terminal
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Terminals
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: tests
Requires-Dist: pytest; extra == 'tests'
Requires-Dist: pytest-cov; extra == 'tests'
Description-Content-Type: text/markdown
# termcolor
[![PyPI version](https://img.shields.io/pypi/v/termcolor.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/termcolor)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/termcolor.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/termcolor)
[![PyPI downloads](https://img.shields.io/pypi/dm/termcolor.svg)](https://pypistats.org/packages/termcolor)
[![GitHub Actions status](https://github.com/termcolor/termcolor/workflows/Test/badge.svg)](https://github.com/termcolor/termcolor/actions)
[![Codecov](https://codecov.io/gh/termcolor/termcolor/branch/main/graph/badge.svg)](https://codecov.io/gh/termcolor/termcolor)
[![Licence](https://img.shields.io/github/license/termcolor/termcolor.svg)](COPYING.txt)
[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)
[![Tidelift](https://tidelift.com/badges/package/pypi/termcolor)](https://tidelift.com/subscription/pkg/pypi-termcolor?utm_source=pypi-termcolor&utm_medium=referral&utm_campaign=readme)
## Installation
### From PyPI
```bash
python3 -m pip install --upgrade termcolor
```
### From source
```bash
git clone https://github.com/termcolor/termcolor
cd termcolor
python3 -m pip install .
```
### Demo
To see demo output, run:
```bash
python3 -m termcolor
```
## Example
```python
import sys
from termcolor import colored, cprint
text = colored("Hello, World!", "red", attrs=["reverse", "blink"])
print(text)
cprint("Hello, World!", "green", "on_red")
print_red_on_cyan = lambda x: cprint(x, "red", "on_cyan")
print_red_on_cyan("Hello, World!")
print_red_on_cyan("Hello, Universe!")
for i in range(10):
cprint(i, "magenta", end=" ")
cprint("Attention!", "red", attrs=["bold"], file=sys.stderr)
# You can also specify 0-255 RGB ints via a tuple
cprint("Both foreground and background can use tuples", (100, 150, 250), (50, 60, 70))
```
## Text properties
| Text colors | Text highlights | Attributes |
| --------------- | ------------------ | ----------- |
| `black` | `on_black` | `bold` |
| `red` | `on_red` | `dark` |
| `green` | `on_green` | `underline` |
| `yellow` | `on_yellow` | `blink` |
| `blue` | `on_blue` | `reverse` |
| `magenta` | `on_magenta` | `concealed` |
| `cyan` | `on_cyan` | `strike` |
| `white` | `on_white` | |
| `light_grey` | `on_light_grey` | |
| `dark_grey` | `on_dark_grey` | |
| `light_red` | `on_light_red` | |
| `light_green` | `on_light_green` | |
| `light_yellow` | `on_light_yellow` | |
| `light_blue` | `on_light_blue` | |
| `light_magenta` | `on_light_magenta` | |
| `light_cyan` | `on_light_cyan` | |
You can also use any arbitrary RGB color specified as a tuple of 0-255 integers, for
example, `(100, 150, 250)`.
## Terminal properties
| Terminal | bold | dark | underline | blink | reverse | concealed |
| ------------ | ------- | ---- | --------- | ---------- | ------- | --------- |
| xterm | yes | no | yes | bold | yes | yes |
| linux | yes | yes | bold | yes | yes | no |
| rxvt | yes | no | yes | bold/black | yes | no |
| dtterm | yes | yes | yes | reverse | yes | yes |
| teraterm | reverse | no | yes | rev/red | yes | no |
| aixterm | normal | no | yes | no | yes | yes |
| PuTTY | color | no | yes | no | yes | no |
| Windows | no | no | no | no | yes | no |
| Cygwin SSH | yes | no | color | color | color | yes |
| Mac Terminal | yes | no | yes | yes | yes | yes |
## Overrides
Terminal colour detection can be disabled or enabled in several ways.
In order of precedence:
1. Calling `colored` or `cprint` with a truthy `no_color` disables colour.
2. Calling `colored` or `cprint` with a truthy `force_color` forces colour.
3. Setting the `ANSI_COLORS_DISABLED` environment variable to any non-empty value
disables colour.
4. Setting the [`NO_COLOR`](https://no-color.org/) environment variable to any non-empty
value disables colour.
5. Setting the [`FORCE_COLOR`](https://force-color.org/) environment variable to any
non-empty value forces colour.
6. Setting the `TERM` environment variable to `dumb`, or using such a
[dumb terminal](https://en.wikipedia.org/wiki/Computer_terminal#Character-oriented_terminal),
disables colour.
7. Finally, termcolor will attempt to detect whether the terminal supports colour.

View File

@@ -0,0 +1,13 @@
termcolor-3.2.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
termcolor-3.2.0.dist-info/METADATA,sha256=iEJwfArFCo6fnwcmBRGZ0cE3UVVA4rOg95y-SzCA6rY,6382
termcolor-3.2.0.dist-info/RECORD,,
termcolor-3.2.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
termcolor-3.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
termcolor-3.2.0.dist-info/licenses/COPYING.txt,sha256=55tr2CliwTMMqqfEInhWewhmd3dnP44jcaYk1XFdTA4,1072
termcolor/__init__.py,sha256=oCqIPpywlruBk5YFDCVd7kSOdtXo0FHXjEXwnt_Pc0E,350
termcolor/__main__.py,sha256=3vLqDeZdeyNRWGpNFSoVv7-zSFeX59QBKjRQCLFMdHI,3520
termcolor/__pycache__/__init__.cpython-312.pyc,,
termcolor/__pycache__/__main__.cpython-312.pyc,,
termcolor/__pycache__/termcolor.cpython-312.pyc,,
termcolor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
termcolor/termcolor.py,sha256=5Kqcff-1g9N2EfAcCY_L5t-GMRAbJR936SuPu3W8bY0,6308

View File

@@ -0,0 +1,4 @@
Wheel-Version: 1.0
Generator: hatchling 1.27.0
Root-Is-Purelib: true
Tag: py3-none-any

View File

@@ -0,0 +1,19 @@
Copyright (c) 2008-2011 Volvox Development Team
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.

View File

@@ -0,0 +1,23 @@
"""ANSI color formatting for output in terminal."""
from __future__ import annotations
from termcolor.termcolor import (
ATTRIBUTES,
COLORS,
HIGHLIGHTS,
RESET,
can_colorize,
colored,
cprint,
)
__all__ = [
"ATTRIBUTES",
"COLORS",
"HIGHLIGHTS",
"RESET",
"can_colorize",
"colored",
"cprint",
]

View File

@@ -0,0 +1,86 @@
from __future__ import annotations
import os
from termcolor import cprint
if __name__ == "__main__":
print(f"Current terminal type: {os.getenv('TERM')}")
print("Test basic colors:")
cprint("Black color", "black")
cprint("Red color", "red")
cprint("Green color", "green")
cprint("Yellow color", "yellow")
cprint("Blue color", "blue")
cprint("Magenta color", "magenta")
cprint("Cyan color", "cyan")
cprint("White color", "white")
cprint("Light grey color", "light_grey")
cprint("Dark grey color", "dark_grey")
cprint("Light red color", "light_red")
cprint("Light green color", "light_green")
cprint("Light yellow color", "light_yellow")
cprint("Light blue color", "light_blue")
cprint("Light magenta color", "light_magenta")
cprint("Light cyan color", "light_cyan")
print("-" * 78)
print("Test highlights:")
cprint("On black color", on_color="on_black")
cprint("On red color", on_color="on_red")
cprint("On green color", on_color="on_green")
cprint("On yellow color", on_color="on_yellow")
cprint("On blue color", on_color="on_blue")
cprint("On magenta color", on_color="on_magenta")
cprint("On cyan color", on_color="on_cyan")
cprint("On white color", color="black", on_color="on_white")
cprint("On light grey color", on_color="on_light_grey")
cprint("On dark grey color", on_color="on_dark_grey")
cprint("On light red color", on_color="on_light_red")
cprint("On light green color", on_color="on_light_green")
cprint("On light yellow color", on_color="on_light_yellow")
cprint("On light blue color", on_color="on_light_blue")
cprint("On light magenta color", on_color="on_light_magenta")
cprint("On light cyan color", on_color="on_light_cyan")
print("-" * 78)
print("Test attributes:")
cprint("Bold black color", "black", attrs=["bold"])
cprint("Dark red color", "red", attrs=["dark"])
cprint("Underline green color", "green", attrs=["underline"])
cprint("Blink yellow color", "yellow", attrs=["blink"])
cprint("Reversed blue color", "blue", attrs=["reverse"])
cprint("Concealed magenta color", "magenta", attrs=["concealed"])
cprint("Strike red color", "red", attrs=["strike"])
cprint(
"Bold underline reverse cyan color",
"cyan",
attrs=["bold", "underline", "reverse"],
)
cprint(
"Dark blink concealed white color",
"white",
attrs=["dark", "blink", "concealed"],
)
print("-" * 78)
print("Test mixing:")
cprint("Underline red on black color", "red", "on_black", ["underline"])
cprint("Reversed green on red color", "green", "on_red", ["reverse"])
print("-" * 78)
print("Test RGB:")
cprint("Pure red text (255, 0, 0)", (255, 0, 0))
cprint("Default red for comparison", "red")
cprint("Pure green text (0, 0, 0)", (0, 255, 0))
cprint("Default green for comparison", "green")
cprint("Pure blue text (0, 0, 0)", (0, 0, 255))
cprint("Default blue for comparison", "blue")
cprint("Pure yellow text (255, 255, 0)", (255, 255, 0))
cprint("Default yellow for comparison", "yellow")
cprint("Pure cyan text (0, 255, 255)", (0, 255, 255))
cprint("Default cyan for comparison", "cyan")
cprint("Pure magenta text (255, 0, 255)", (255, 0, 255))
cprint("Default magenta for comparison", "magenta")
cprint("Light pink (255, 182, 193)", (255, 182, 193))
cprint("Light pink (255, 105, 180)", (255, 105, 180))

View File

@@ -0,0 +1,215 @@
# Copyright (c) 2008-2011 Volvox Development Team
#
# 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.
#
# Author: Konstantin Lepa <konstantin.lepa@gmail.com>
"""ANSI color formatting for output in terminal."""
from __future__ import annotations
import io
import os
import sys
from functools import cache
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Iterable
from typing import Any
ATTRIBUTES: dict[str, int] = {
"bold": 1,
"dark": 2,
"underline": 4,
"blink": 5,
"reverse": 7,
"concealed": 8,
"strike": 9,
}
HIGHLIGHTS: dict[str, int] = {
"on_black": 40,
"on_grey": 40, # Actually black but kept for backwards compatibility
"on_red": 41,
"on_green": 42,
"on_yellow": 43,
"on_blue": 44,
"on_magenta": 45,
"on_cyan": 46,
"on_light_grey": 47,
"on_dark_grey": 100,
"on_light_red": 101,
"on_light_green": 102,
"on_light_yellow": 103,
"on_light_blue": 104,
"on_light_magenta": 105,
"on_light_cyan": 106,
"on_white": 107,
}
COLORS: dict[str, int] = {
"black": 30,
"grey": 30, # Actually black but kept for backwards compatibility
"red": 31,
"green": 32,
"yellow": 33,
"blue": 34,
"magenta": 35,
"cyan": 36,
"light_grey": 37,
"dark_grey": 90,
"light_red": 91,
"light_green": 92,
"light_yellow": 93,
"light_blue": 94,
"light_magenta": 95,
"light_cyan": 96,
"white": 97,
}
RESET = "\033[0m"
@cache
def can_colorize(
*, no_color: bool | None = None, force_color: bool | None = None
) -> bool:
"""Check env vars and for tty/dumb terminal"""
# First check overrides:
# "User-level configuration files and per-instance command-line arguments should
# override $NO_COLOR. A user should be able to export $NO_COLOR in their shell
# configuration file as a default, but configure a specific program in its
# configuration file to specifically enable color."
# https://no-color.org
if no_color is not None and no_color:
return False
if force_color is not None and force_color:
return True
# Then check env vars:
if os.environ.get("ANSI_COLORS_DISABLED"):
return False
if os.environ.get("NO_COLOR"):
return False
if os.environ.get("FORCE_COLOR"):
return True
# Then check system:
if os.environ.get("TERM") == "dumb":
return False
if not hasattr(sys.stdout, "fileno"):
return False
try:
return os.isatty(sys.stdout.fileno())
except io.UnsupportedOperation:
return sys.stdout.isatty()
def colored(
text: object,
color: str | tuple[int, int, int] | None = None,
on_color: str | tuple[int, int, int] | None = None,
attrs: Iterable[str] | None = None,
*,
no_color: bool | None = None,
force_color: bool | None = None,
) -> str:
"""Colorize text.
Available text colors:
black, red, green, yellow, blue, magenta, cyan, white,
light_grey, dark_grey, light_red, light_green, light_yellow, light_blue,
light_magenta, light_cyan.
Available text highlights:
on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white,
on_light_grey, on_dark_grey, on_light_red, on_light_green, on_light_yellow,
on_light_blue, on_light_magenta, on_light_cyan.
Alternatively, both text colors (color) and highlights (on_color) may
be specified via a tuple of 0-255 ints (R, G, B).
Available attributes:
bold, dark, underline, blink, reverse, concealed.
Example:
colored('Hello, World!', 'red', 'on_black', ['bold', 'blink'])
colored('Hello, World!', 'green')
colored('Hello, World!', (255, 0, 255)) # Purple
"""
result = str(text)
if not can_colorize(no_color=no_color, force_color=force_color):
return result
fmt_str = "\033[%dm%s"
rgb_fore_fmt_str = "\033[38;2;%d;%d;%dm%s"
rgb_back_fmt_str = "\033[48;2;%d;%d;%dm%s"
if color is not None:
if isinstance(color, str):
result = fmt_str % (COLORS[color], result)
elif isinstance(color, tuple):
result = rgb_fore_fmt_str % (color[0], color[1], color[2], result)
if on_color is not None:
if isinstance(on_color, str):
result = fmt_str % (HIGHLIGHTS[on_color], result)
elif isinstance(on_color, tuple):
result = rgb_back_fmt_str % (on_color[0], on_color[1], on_color[2], result)
if attrs is not None:
for attr in attrs:
result = fmt_str % (ATTRIBUTES[attr], result)
result += RESET
return result
def cprint(
text: object,
color: str | tuple[int, int, int] | None = None,
on_color: str | tuple[int, int, int] | None = None,
attrs: Iterable[str] | None = None,
*,
no_color: bool | None = None,
force_color: bool | None = None,
**kwargs: Any,
) -> None:
"""Print colorized text.
It accepts arguments of print function.
"""
print(
(
colored(
text,
color,
on_color,
attrs,
no_color=no_color,
force_color=force_color,
)
),
**kwargs,
)