sqlite-colorbrewer by eyeseast

标星

README 源代码

sqlite-colorbrewer

PyPI Changelog Tests License

一个自定义函数,用于在 SQLite 查询中使用 ColorBrewer 色阶。

颜色数据从此处导出。

安装

安装为 Python 库并与标准 SQLite3 模块一起使用

pip install sqlite-colorbrewer

要在与 Datasette 相同的环境中安装此插件。

datasette install sqlite-colorbrewer

用法

如果您在 Datasette 中使用此库,它将自动注册为插件,并可在 SQL 查询中使用,例如:

SELECT colorbrewer('Blues', 9, 0);

这将返回一个值: "rgb(247,251,255)"

要在 Datasette 之外使用 SQLite 连接,请使用 register 函数

>> result = next(cursor) >>> print(result) rgb(247,251,255)">
>>> import sqlite3
>>> import sqlite_colorbrewer

>>> conn = sqlite3.connect(':memory')
>>> sqlite_colorbrewer.register(conn)

>>> cursor = conn.execute("SELECT colorbrewer('Blues', 9, 0);")
>>> result = next(cursor)
>>> print(result)
rgb(247,251,255)

开发

要在本地设置此插件,请先检出代码。然后创建一个新的虚拟环境

cd sqlite-colorbrewer
python3 -mvenv venv
source venv/bin/activate

或者如果您正在使用 pipenv

pipenv shell

现在安装依赖项和测试依赖项

pip install -e '.[test]'

运行测试

pytest

构建 sqlite_colorbrewer/colorbrewer.py

./json_to_python.py
black . # to format the resulting file

ColorBrewer

版权所有 (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.

根据 Apache 许可证 2.0 版 (“许可证”) 授权;除非符合许可证规定,否则不得使用此文件。您可以获取许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,根据许可证分发的软件按“现状”提供,不带任何明示或暗示的保证或条件。有关权限和限制的具体语言,请参阅许可证。

有关版权信息的更新,请参阅ColorBrewer 更新