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 3 months ago
dist e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago
simplemotds e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago
GPLv3.txt 4038e02236 Initial commit package 3 months ago
LICENSE.txt 4038e02236 Initial commit package 3 months ago
MANIFEST.in e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago
README.md e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago
README.txt e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago
setup.cfg 0b7da45bfd [+-] setup.py, MANIFEST, dist 3 months ago
setup.py e8c16ca7ef [fix] external configuration json file [+-] READMEs 3 months ago

README.md

Simple motds

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.

Initialization

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)

SimpleMotd methods

  • 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.

Modifying configuration file

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:

    • month
    • week
    • hour
    • day
    • minute
  • 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:

    • random
    • alphabetically-desc
    • alphabetically-asc
    • modification-asc
    • modification-desc
    • formula (not implemented yet)
  • 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.