旧BSD Unix fortune程序的Python版本
项目描述
幸运
简介
fortunate
是经典BSD Unix fortune
命令的简化实现。它结合了 strfile
命令(生成幸运指数文件)和 fortunate
命令(显示随机幸运语句)的功能。它读取传统 fortune
程序的文本文件格式。
此存储库包含一个 幸运饼干数据库。它包含自1990年左右收集的2800多条引用。
用法
用作命令行工具时
Usage: fortunate [OPTIONS] [fortune_files ...]
Options:
-h, --help show this help message and exit
-v, --verbose when updating the index file, emit verbose messages
-u, --update update the index file, instead of printing a fortune.
-V, --version show version and exit.
-n NUM number of fortune cookies to show
如果您省略了幸运文件/路径,fortunate
将查看 FORTUNE_FILE
环境变量。如果没有设置该环境变量,fortunate
将在 /usr/local/share/games/fortunes
中查找,否则将终止。
用作Python库时
from fortunate import Fortunate
generator = Fortunate('/path/to/fortunes')
print(generator())
幸运饼干文件格式
幸运饼干文件是一个充满引用的文本文件。格式简单:文件由包含单个 '%' 字符的行分隔的段落组成。例如
A little caution outflanks a large cavalry.
-- Bismarck
%
A little retrospection shows that although many fine, useful software
systems have been designed by committees and built as part of multipart
projects, those software systems that have excited passionate fans are
those that are the products of one or a few designing minds, great
designers. Consider Unix, APL, Pascal, Modula, the Smalltalk interface,
even Fortran; and contrast them with Cobol, PL/I, Algol, MVS/370, and
MS-DOS.
-- Fred Brooks, Jr.
%
A man is not old until regrets take the place of dreams.
-- John Barrymore
索引文件
为了提高效率和速度,fortunate
使用索引文件来存储文本幸运文件中每个幸运内容的偏移量和长度。因此,在您使用 fortunate
读取随机幸运内容之前,您必须生成数据文件。在传统的 BSD fortunate
程序中,您使用 strfile(8) 命令来生成索引。然而,在这个 fortune 程序中,索引将自动在用户的家目录中生成,位于 ~/.fortunate
。
每次更改文本幸运文件时,您都应该运行 fortunate -u
,以便生成新的索引。
生成随机幸运内容
您可以通过运行 fortunate
实用程序并指定您的文本幸运文件路径来生成随机幸运内容。
fortunate /path/to/fortunes
差异
这个版本的 fortunate
没有提供原始 BSD 程序的一些更高级功能。例如,它缺少:
- 标记冒犯性和非冒犯性幸运内容的可能性
- 区分长引号和短引号的可能性
- 打印匹配正则表达式的所有幸运内容的可能性
然而,它确实提供了最重要的功能:从一组引语中显示随机引语的能力。
许可证和版权信息
这是一个免费软件,根据以下类似 BSD 许可证发布
Copyright (c) 2018 German Mendez Bravo (Kronuz)
Copyright (c) 2008 Brian M. Clapper
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- The end-user documentation included with the redistribution, if any,
must include the following acknowlegement:
This product includes software developed by Brian M. Clapper
(bmc@clapper.org, http://www.clapper.org/bmc/). That software is
copyright (c) 2008 Brian M. Clapper.
Alternately, this acknowlegement may appear in the software itself, if
and wherever such third-party acknowlegements normally appear.
THIS SOFTWARE IS PROVIDED AS IS AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRIAN M.
CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
这个幸运文件数据库是根据 Creative Commons Attribution 4.0 国际许可证提供的。有关详细信息,请参阅 http://creativecommons.org/licenses/by/4.0/legalcode。
项目详情
fortunate-1.4.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 76e0d43daf115aa2a241d672aecb5cf595ac1b16efd7b25d23e200a2beff1eaa |
|
MD5 | 9e3683c746b27b6805f295966f7a1458 |
|
BLAKE2b-256 | ad5fa474a5c4a118e8aafaafdb541768aa8289c1c2014b6b81d68c96f4f9ca5c |