A simple configurable python module to get the message of the day from files inside a given folder
Rodrigo Garcia e8c16ca7ef [fix] external configuration json file [+-] READMEs | %!s(int64=6) %!d(string=hai) anos | |
---|---|---|
dist | %!s(int64=6) %!d(string=hai) anos | |
simplemotds | %!s(int64=6) %!d(string=hai) anos | |
GPLv3.txt | %!s(int64=6) %!d(string=hai) anos | |
LICENSE.txt | %!s(int64=6) %!d(string=hai) anos | |
MANIFEST.in | %!s(int64=6) %!d(string=hai) anos | |
README.md | %!s(int64=6) %!d(string=hai) anos | |
README.txt | %!s(int64=6) %!d(string=hai) anos | |
setup.cfg | %!s(int64=6) %!d(string=hai) anos | |
setup.py | %!s(int64=6) %!d(string=hai) anos |
Simple module to get the message of the day (motd), every motd should be in a separate file inside (by default) messages/
folder.
The module returns a different motd every day, month, week, hour or minute, the time period which the message should be changed is defined in the simple configuration file config.json
.
pip install simplemotds
A SimpleMotd
object should be created and use its attributes.
from simple_motd import SimpleMotd
simplemotd = SimpleMotd() # To use default config.json (placed on the package root)
simplemotd = SimpleMotd(external_config_json_file="another.json") # To use different configuration file (placed anywhere you want)
external_config_json_file
: See configuration file details.getMotdContent()
: returns the contents of the current message by reading it's file inside the messages
folder. Contents are returned as a python string using utf-8 enconding by default.getMotdFile()
: returns a python file object (opened) to the current message.getMotdFileName()
: returns the file name of the current message.ForceNextMessage()
: Forces to change the message by selecting another file inside messages
or other configured folder, returns the new filename.All is done in the file config.json
, defaults:
{
"time-period": "day",
"folder": "./messages",
"selection-type": "random"
}
time-period: Specifies the time period to change the message returned. Valid values:
folder: The folder where to look for the messages, every message must be in a separate file of any extension, for instance create a "motds"
and place there all messages in separete files, then put "motds"
on the .json file.
selection-type: How to get the messages, it can be:
alphabetically-desc
gets files by its name in a descendent order (a first and z last), alphabetically-asc
(z first, a last). modification-asc/desc
considers the last time of modification of the files as ordering rule.