Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import os
- import configparser
- journal_dirname = ""
- journal_cwd = ""
- journal_date = ""
- journal_filename = ""
- journal_ext = ""
- journal_editor = ""
- journal_datefmt = ""
- #
- # Example jour.ini (blog.ini, work.ini, ...)
- #
- # [settings]
- # path=C:\Source\journal
- # editor=notepad
- # ext=.md
- # dateformat=%%Y\%%m-%%d
- #
- def read_settings(inifile):
- global journal_dirname
- global journal_cwd
- global journal_ext
- global journal_editor
- global journal_datefmt
- journal_cwd = sys.path[0]
- config = configparser.ConfigParser()
- config.read(os.path.join(journal_cwd, inifile))
- try:
- journal_dirname = config.get("settings", "path")
- except:
- journal_dirname = journal_cwd
- try:
- journal_editor = config.get("settings", "editor")
- except:
- journal_editor = "notepad"
- try:
- journal_datefmt = config.get("settings", "dateformat")
- except:
- print("Unexpected error:", sys.exc_info()[0])
- journal_datefmt = "%Y-%b-%d"
- try:
- journal_ext = config.get("settings", "ext")
- except:
- journal_ext = ".txt"
- if journal_ext == "":
- journal_ext = ".txt"
- def main():
- global journal_filename
- global journal_date
- global journal_datefmt
- # Default ini file
- inifile = "jour.ini"
- # Read optional ini file override as first argument
- if len(sys.argv) > 1:
- inifile = sys.argv[1] + ".ini"
- read_settings(inifile)
- # Create a new filename of the format "2004-01-03".
- journal_date = time.strftime(journal_datefmt, time.localtime())
- # Allow an optional prefix for subjournals.
- journal_name = journal_date
- if len(sys.argv) > 2:
- journal_name = journal_date + "-" + sys.argv[2]
- journal_filename = os.path.join(journal_dirname, journal_name + journal_ext)
- # Edit the journal entry
- os.system(journal_editor + " " + journal_filename)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement