README.txt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Simple motds
  2. Simple module to get the message of the day (motd), every motd should be in a separate file inside (by default) `messages/` folder.
  3. 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`.
  4. ## Initialization
  5. pip install simplemotds
  6. A `SimpleMotd` object should be created and use its attributes.
  7. from simple_motd import SimpleMotd
  8. simplemotd = SimpleMotd() # To use default config.json (placed on the package root)
  9. simplemotd = SimpleMotd(external_config_json_file="another.json") # To use different configuration file (placed anywhere you want)
  10. * `external_config_json_file`: See [configuration file details](#modifying-configuration-file).
  11. ### SimpleMotd methods
  12. * `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.
  13. * `getMotdFile()`: returns a python file object (opened) to the current message.
  14. * `getMotdFileName()`: returns the file name of the current message.
  15. * `ForceNextMessage()`: Forces to change the message by selecting another file inside `messages` or other configured folder, returns the new filename.
  16. ## Modifying configuration file
  17. All is done in the file `config.json`, defaults:
  18. {
  19. "time-period": "day",
  20. "folder": "./messages",
  21. "selection-type": "random"
  22. }
  23. - **time-period**: Specifies the time period to change the message returned. Valid values:
  24. - month
  25. - week
  26. - hour
  27. - day
  28. - minute
  29. - **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.
  30. - **selection-type**: How to get the messages, it can be:
  31. - random
  32. - alphabetically-desc
  33. - alphabetically-asc
  34. - modification-asc
  35. - modification-desc
  36. - formula <numeric formula> (not implemented yet)
  37. `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.