diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-09-06 16:13:50 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-09-06 16:13:50 -0400 |
commit | 5b29d620e0cf59b314f3d47457b67b9a39e27d7d (patch) | |
tree | 33a964bf8efbc10096a0419e6e2a205d99d043cf | |
parent | d7bb3986c104076a2793aa8a89a9292968999564 (diff) | |
download | weekly_og-5b29d620e0cf59b314f3d47457b67b9a39e27d7d.tar.gz |
Initial commit
-rw-r--r-- | pyproject.toml | 6 | ||||
-rw-r--r-- | setup.py | 17 | ||||
-rw-r--r-- | weekly/__init__.py | 6 | ||||
-rw-r--r-- | weekly/weekly.py | 105 |
4 files changed, 134 insertions, 0 deletions
diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4a3eab1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=30.3.0", + "wheel", + "setuptools_scm" +] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f2f0590 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +from setuptools import setup, find_packages + +setup( + name="weekly", + use_scm_version=True, + setup_requires=[ + 'setuptools_scm' + ], + description='A basic microblog for weekly reports', + license='BSD', + package=find_packages(), + entry_points={ + 'console_scripts': [ + 'weekly=weekly.weekly:main' + ], + }, +) diff --git a/weekly/__init__.py b/weekly/__init__.py new file mode 100644 index 0000000..873e2c3 --- /dev/null +++ b/weekly/__init__.py @@ -0,0 +1,6 @@ +from pkg_resources import get_distribution, DistributionNotFound +try: + __version__ = get_distribution(__name__).version +except DistributionNotFound: + # package is not installed + __version__ = 'unknown' diff --git a/weekly/weekly.py b/weekly/weekly.py new file mode 100644 index 0000000..076192a --- /dev/null +++ b/weekly/weekly.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +import argparse +import os +import datetime +from subprocess import Popen +from . import __version__ + + +def user_message(tm, status): + banner = '=' * 80 + marker = '{0}\n{1}\n{2}\n{0}'.format(banner, tm, status) + done = False + lines = [] + + while not done: + msg = '' + output = '' + + try: + print('>>>', end='') + msg = input() + except EOFError: + done = True + + if msg == '.' or msg == 'EOF': + done = True + + if not done: + if len(lines) < 1: + lines.append(marker) + lines.append(msg) + + if lines: + output = '\n'.join([x for x in lines]) + output += '\n' + + return output + + +def show_messages(path): + for root, dirs, files in os.walk(path): + for f in sorted(files, reverse=False): + ingest = os.path.join(root, f) + with open(ingest, 'r') as fp: + for line in fp: + print(line.rstrip()) + + +def main(): + DATA = os.path.abspath(os.path.expanduser('~/.reports/data')) + now = datetime.datetime.now() + year, weekno, day = now.isocalendar() + + if not os.path.exists(DATA): + os.makedirs(DATA) + + todays_path = os.path.join(DATA, str(year), str(weekno)) + todays_file = os.path.join(todays_path, str(day)) + + if not os.path.exists(todays_path): + os.makedirs(todays_path) + + parser = argparse.ArgumentParser() + parser.add_argument('-i', '--important', action='store_true', + required=False) + parser.add_argument('-r', '--retrieve', action='store_true') + parser.add_argument('-e', '--edit', action='store_true') + parser.add_argument('-V', '--version', action='store_true') + args = parser.parse_args() + + if args.version: + print(__version__) + return 0 + + if args.edit: + editor = '/usr/bin/vim' + if 'EDITOR' in os.environ: + editor = os.environ['EDITOR'] + command = ' '.join([editor, todays_file]) + proc = Popen(command.split()) + proc.communicate() + retval = proc.wait() + if retval is None: + retval = 1 + + return retval + + if args.retrieve: + show_messages(todays_path) + return 0 + + status = 'NOTE' + if args.important: + status = 'IMPORTANT' + + message = user_message(now, status) + with open(todays_file, 'a') as fp: + fp.write(message) + fp.write(os.linesep) + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) |