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 | 6 years ago | |
---|---|---|
dist | 6 years ago | |
simplemotds | 6 years ago | |
GPLv3.txt | 6 years ago | |
LICENSE.txt | 6 years ago | |
MANIFEST.in | 6 years ago | |
README.md | 6 years ago | |
README.txt | 6 years ago | |
setup.cfg | 6 years ago | |
setup.py | 6 years ago |
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.