summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne-Cole <77279425+Wacky404@users.noreply.github.com>2024-12-18 21:37:34 -0600
committerWayne-Cole <77279425+Wacky404@users.noreply.github.com>2024-12-18 21:37:34 -0600
commit5b94345217a6461091bfda17de75b7e07bd5e9a3 (patch)
treeda26192bcd4bf1ddda62c27dc8b51ef3137bd307
parentfeb972adcce374893bc999133dbe85328e30f387 (diff)
downloadworklogger-5b94345217a6461091bfda17de75b7e07bd5e9a3.tar.xz
worklogger-5b94345217a6461091bfda17de75b7e07bd5e9a3.zip
chore: updating files
-rw-r--r--src/__pycache__/args_worklogger.cpython-312.pycbin2426 -> 0 bytes
-rw-r--r--src/args_worklogger.py49
-rw-r--r--src/funcs_worklogger.py46
-rw-r--r--src/funcs_worklogger.pyi20
-rw-r--r--src/logs/WorkLogger.log32
-rwxr-xr-xsrc/worklog8
6 files changed, 138 insertions, 17 deletions
diff --git a/src/__pycache__/args_worklogger.cpython-312.pyc b/src/__pycache__/args_worklogger.cpython-312.pyc
deleted file mode 100644
index 90aa3c6..0000000
--- a/src/__pycache__/args_worklogger.cpython-312.pyc
+++ /dev/null
Binary files differ
diff --git a/src/args_worklogger.py b/src/args_worklogger.py
index 70c3775..836cc7f 100644
--- a/src/args_worklogger.py
+++ b/src/args_worklogger.py
@@ -5,7 +5,6 @@ author: Wacky404
email: wacky404@dev.com
"""
-from pathlib import Path
import argparse
parser = argparse.ArgumentParser(
@@ -14,11 +13,6 @@ parser = argparse.ArgumentParser(
"directly from the terminal you work in.",
)
-subparsers = parser.add_subparsers()
-
-parser_email = subparsers.add_parser(
- 'email', help='Send an email of your worklog(s)')
-
parser.add_argument(
'-c',
'--configure',
@@ -41,10 +35,11 @@ parser.add_argument(
parser.add_argument(
'-v',
'--verbose',
- action='store_false',
- help='turn on/off the verboseness of the program when run',
+ action='store_true',
+ help='Turn on a verbose program when run',
)
+
parser.add_argument(
'job',
action='store',
@@ -94,12 +89,44 @@ parser.add_argument(
help='Add a message to accompany your worklog entry'
)
+subparsers = parser.add_subparsers(help='subcommand help')
+
+parser_merge = subparsers.add_parser(
+ 'merge', help='Merge Records of a job and specified file extension'
+)
+
+# Merge Functionality
+parser_merge.add_argument(
+ '-ext',
+ '--extension',
+ action='store',
+ choices=['csv', 'text', 'json'],
+ default='csv',
+ help='(required) Output file type, as a result of merge'
+)
+
+parser_merge.add_argument(
+ '--exttarget',
+ action='store',
+ choices=['csv', 'text', 'json'],
+ help='Target a specific file type to merge into one file'
+)
+
+parser_merge.add_argument(
+ '--delete',
+ action='store_true',
+ help='Delete the old individual files that will get merged into one file'
+)
+
+parser_email = subparsers.add_parser(
+ 'email', help='Send an email of your worklog(s)')
+
# Email Functionality
parser_email.add_argument(
'-s',
'--sender',
action='store',
- help='whom will be sending the email, if email is provided in config this flag does not need to be used'
+ help='Whom will be sending the email, if email is provided in config this flag does not need to be used'
)
parser_email.add_argument(
@@ -107,7 +134,7 @@ parser_email.add_argument(
'--recipient',
required=True,
action='store',
- help='whom will be recieving the email'
+ help='(required) Whom will be recieving the email'
)
parser_email.add_argument(
@@ -116,5 +143,5 @@ parser_email.add_argument(
nargs='+',
action='store',
required=True,
- help='path(s) to file or directory you want to email'
+ help='Path(s) to file or directory you want to email'
)
diff --git a/src/funcs_worklogger.py b/src/funcs_worklogger.py
index c2b5acf..b645af8 100644
--- a/src/funcs_worklogger.py
+++ b/src/funcs_worklogger.py
@@ -1,4 +1,5 @@
#!/opt/homebrew/bin/python3
+
"""
IMPLEMENTATION FILE FOR WORKLOGGER
author: Wacky404
@@ -45,7 +46,6 @@ def parse(filepath=None):
return lines
elif ext == '.csv':
- # TODO: format returned list of str to what we are expecting; job:example loc:place
lines = []
with open(filepath, 'r') as fd:
csv_reader = csv.DictReader(fd, delimiter=',')
@@ -202,5 +202,49 @@ def add_log(file_format=None, proj_settings=None, savepath=None, backuppath=None
logger.info(f"Written {kwargs['job']} worklog to {path}")
+def combine_log(specified_ext, target_job, target_extension=None, savepath=None, backuppath=None, delete=False):
+ # you pick a job then if you want you can choose a specific file type to target for combining into your specified_ext
+ # TODO: Finish function stopped just before date sorting; getting a data structure prepped for sorting then transformation
+ if target_job is None:
+ logger.info('You must specify a job to run combine_log()')
+ return None
+
+ for dir in (savepath, backuppath):
+ buffer = []
+ if osp.exists(dir):
+ target_extension = target_extension.strip('.')
+ # only thing affected by this blocks if statement
+ if target_extension is not None:
+ files = list(Path(dir).glob(
+ f'**/{target_job.upper()}.{target_extension}'))
+ else:
+ files = list(Path(dir).glob(f'**/{target_job.upper()}'))
+ logger.debug(f"Found file(s): {files}")
+ if len(files) < 2:
+ logger.exception(
+ f'combine_log() reqs 2 or more files. Found less than 2 of {target_job.upper()}.{target_extension}')
+ return None
+
+ for file in files:
+ buffer.append(*parse(file))
+
+ for index, line in enumerate(buffer):
+ buffer[index] = [index, line]
+
+ for content in buffer:
+ _entry = content[1].split(' ')
+ for param in _entry:
+ param_split = param.split(':')
+ var, val = param_split[0], param_split[1] if len(
+ param_split) == 2 else None
+ # need to sort datetimes ... actually easy
+ if var == 'timestamp':
+ buffer[content[0]].append(val)
+
+ buffer.sort(key=lambda x: datetime.strptime(
+ x[2], "%Y-%m-%dT%H:%M:%S%Z"))
+ pprint(buffer)
+
+
def send_email(sender=None, to=None, subject=None, files=None):
pass
diff --git a/src/funcs_worklogger.pyi b/src/funcs_worklogger.pyi
index fd3d46f..2a90cb5 100644
--- a/src/funcs_worklogger.pyi
+++ b/src/funcs_worklogger.pyi
@@ -6,23 +6,35 @@ email: wacky404@dev.com
from argparse import Namespace
from pathlib import Path
+from typing import Optional
-def configure(dir_list: list | None) -> None:
+def configure(dir_list: Optional[list]) -> None:
"""
-
+
+ """
+ ...
+
+
+def add_log(file_format: Optional[str], proj_settings: Optional[dict[str, dict]], savepath: Optional[Path], backuppath: Optional[Path], **kwargs) -> None:
+ # small bug in function that is missing an unchecked log start time
+ """
+
"""
...
-def add_log(file_format: str | None, proj_settings: dict[str, dict] | None, savepath: Path | str, backuppath: Path | str, **kwargs) -> None:
+def combine_log(specified_ext: str, target_file: Path, target_extension: Optional[str],
+ savepath: Optional[Path], backuppath: Optional[Path], delete: bool = False, **kwargs) -> None:
"""
+ Combine logs of different file types into one file of a specified type.
"""
...
-def parse(filepath: Path | str) -> list:
+def parse(filepath: Optional[Path]) -> list:
+ # add json parsing, eventually
"""
"""
diff --git a/src/logs/WorkLogger.log b/src/logs/WorkLogger.log
index e57cf33..932bace 100644
--- a/src/logs/WorkLogger.log
+++ b/src/logs/WorkLogger.log
@@ -646,3 +646,35 @@ PermissionError: [Errno 13] Permission denied: '/Users/cole/../NOT SO GREAT COMP
[DEBUG|funcs_worklogger|L172] 2024-10-17T16:52:45-0500: Job: uasys; Projects: {'GENERAL': 'anything'}
[INFO|funcs_worklogger|L210] 2024-10-17T16:52:45-0500: Written uasys worklog to /Users/cole/Documents/GitHub/worklogger/Output
[INFO|funcs_worklogger|L210] 2024-10-17T16:52:45-0500: Written uasys worklog to /Users/cole/Documents/worklogger
+[DEBUG|worklog|L50] 2024-11-28T20:45:40-0600: Found dotfile(s): [PosixPath('/Users/cole/.config/.workloggerconfig.json')]
+[DEBUG|worklog|L56] 2024-11-28T20:45:40-0600: Using user config file in /Users/cole/.config/.workloggerconfig.json
+[DEBUG|worklog|L92] 2024-11-28T20:45:40-0600: {'GREAT COMPANY': {'proj 1': 'null', 'proj 2': '0987654321', 'proj 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'codename: secrete': '404', 'govwork': '902753203', 'exemplary': '9023hdalw903'}, 'UASYS': {'General': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'Interconnection': 'InterConnection Queue'}, 'EPRI': {'GridFast': '12345', 'Exemplar': '12345'}}
+[DEBUG|worklog|L101] 2024-11-28T20:45:40-0600: {'GREAT COMPANY': {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'CODENAME: SECRETE': '404', 'GOVWORK': '902753203', 'EXEMPLARY': '9023hdalw903'}, 'UASYS': {'GENERAL': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'INTERCONNECTION': 'InterConnection Queue'}, 'EPRI': {'GRIDFAST': '12345', 'EXEMPLAR': '12345'}}
+[DEBUG|funcs_worklogger|L41] 2024-11-28T20:45:40-0600: Parsed: GREAT COMPANY, .csv
+[DEBUG|funcs_worklogger|L164] 2024-11-28T20:45:40-0600: Job: great company; Projects: {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}
+[INFO|funcs_worklogger|L202] 2024-11-28T20:45:40-0600: Written great company worklog to /Users/cole/Documents/GitHub/worklogger/Output
+[INFO|funcs_worklogger|L202] 2024-11-28T20:45:40-0600: Written great company worklog to /Users/cole/Documents/worklogger
+[DEBUG|worklog|L50] 2024-11-28T20:48:55-0600: Found dotfile(s): [PosixPath('/Users/cole/.config/.workloggerconfig.json')]
+[DEBUG|worklog|L56] 2024-11-28T20:48:55-0600: Using user config file in /Users/cole/.config/.workloggerconfig.json
+[DEBUG|worklog|L92] 2024-11-28T20:48:55-0600: {'GREAT COMPANY': {'proj 1': 'null', 'proj 2': '0987654321', 'proj 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'codename: secrete': '404', 'govwork': '902753203', 'exemplary': '9023hdalw903'}, 'UASYS': {'General': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'Interconnection': 'InterConnection Queue'}, 'EPRI': {'GridFast': '12345', 'Exemplar': '12345'}}
+[DEBUG|worklog|L101] 2024-11-28T20:48:55-0600: {'GREAT COMPANY': {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'CODENAME: SECRETE': '404', 'GOVWORK': '902753203', 'EXEMPLARY': '9023hdalw903'}, 'UASYS': {'GENERAL': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'INTERCONNECTION': 'InterConnection Queue'}, 'EPRI': {'GRIDFAST': '12345', 'EXEMPLAR': '12345'}}
+[DEBUG|funcs_worklogger|L41] 2024-11-28T20:48:55-0600: Parsed: GREAT COMPANY, .txt
+[DEBUG|funcs_worklogger|L134] 2024-11-28T20:48:55-0600: Job: great company; Projects: {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}
+[INFO|funcs_worklogger|L202] 2024-11-28T20:48:55-0600: Written great company worklog to /Users/cole/Documents/GitHub/worklogger/Output
+[INFO|funcs_worklogger|L202] 2024-11-28T20:48:55-0600: Written great company worklog to /Users/cole/Documents/worklogger
+[DEBUG|worklog|L50] 2024-11-28T20:50:36-0600: Found dotfile(s): [PosixPath('/Users/cole/.config/.workloggerconfig.json')]
+[DEBUG|worklog|L56] 2024-11-28T20:50:36-0600: Using user config file in /Users/cole/.config/.workloggerconfig.json
+[DEBUG|worklog|L92] 2024-11-28T20:50:36-0600: {'GREAT COMPANY': {'proj 1': 'null', 'proj 2': '0987654321', 'proj 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'codename: secrete': '404', 'govwork': '902753203', 'exemplary': '9023hdalw903'}, 'UASYS': {'General': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'Interconnection': 'InterConnection Queue'}, 'EPRI': {'GridFast': '12345', 'Exemplar': '12345'}}
+[DEBUG|worklog|L101] 2024-11-28T20:50:36-0600: {'GREAT COMPANY': {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'CODENAME: SECRETE': '404', 'GOVWORK': '902753203', 'EXEMPLARY': '9023hdalw903'}, 'UASYS': {'GENERAL': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'INTERCONNECTION': 'InterConnection Queue'}, 'EPRI': {'GRIDFAST': '12345', 'EXEMPLAR': '12345'}}
+[DEBUG|funcs_worklogger|L41] 2024-11-28T20:50:36-0600: Parsed: GREAT COMPANY, .csv
+[DEBUG|funcs_worklogger|L164] 2024-11-28T20:50:36-0600: Job: great company; Projects: {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}
+[INFO|funcs_worklogger|L202] 2024-11-28T20:50:36-0600: Written great company worklog to /Users/cole/Documents/GitHub/worklogger/Output
+[INFO|funcs_worklogger|L202] 2024-11-28T20:50:36-0600: Written great company worklog to /Users/cole/Documents/worklogger
+[DEBUG|worklog|L50] 2024-11-28T20:50:51-0600: Found dotfile(s): [PosixPath('/Users/cole/.config/.workloggerconfig.json')]
+[DEBUG|worklog|L56] 2024-11-28T20:50:51-0600: Using user config file in /Users/cole/.config/.workloggerconfig.json
+[DEBUG|worklog|L92] 2024-11-28T20:50:51-0600: {'GREAT COMPANY': {'proj 1': 'null', 'proj 2': '0987654321', 'proj 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'codename: secrete': '404', 'govwork': '902753203', 'exemplary': '9023hdalw903'}, 'UASYS': {'General': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'Interconnection': 'InterConnection Queue'}, 'EPRI': {'GridFast': '12345', 'Exemplar': '12345'}}
+[DEBUG|worklog|L101] 2024-11-28T20:50:51-0600: {'GREAT COMPANY': {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}, 'NOT SO GREAT COMPANY': {'CODENAME: SECRETE': '404', 'GOVWORK': '902753203', 'EXEMPLARY': '9023hdalw903'}, 'UASYS': {'GENERAL': 'anything', 'EI': 'Educational Institution'}, 'PACES': {'INTERCONNECTION': 'InterConnection Queue'}, 'EPRI': {'GRIDFAST': '12345', 'EXEMPLAR': '12345'}}
+[DEBUG|funcs_worklogger|L41] 2024-11-28T20:50:51-0600: Parsed: GREAT COMPANY, .csv
+[DEBUG|funcs_worklogger|L164] 2024-11-28T20:51:15-0600: Job: great company; Projects: {'PROJ 1': 'null', 'PROJ 2': '0987654321', 'PROJ 3': '1234567890'}
+[INFO|funcs_worklogger|L202] 2024-11-28T20:51:15-0600: Written great company worklog to /Users/cole/Documents/GitHub/worklogger/Output
+[INFO|funcs_worklogger|L202] 2024-11-28T20:51:15-0600: Written great company worklog to /Users/cole/Documents/worklogger
diff --git a/src/worklog b/src/worklog
index 2b4dca8..b981201 100755
--- a/src/worklog
+++ b/src/worklog
@@ -13,10 +13,13 @@ import os
import os.path as osp
import logging
import paths_util_worklogger as pu
-from funcs_worklogger import configure, add_log, arg_convert
+from funcs_worklogger import configure, add_log
from args_worklogger import parser
from pathlib import Path
from log_util_worklogger import logger, setup_logging
+from typing import Optional
+
+from pprint import pprint
SAVEPATH: Path | str
@@ -30,6 +33,8 @@ formats: dict = {
# creates a NameSpace of arguments that were made
args = parser.parse_args()
+pprint(args)
+sys.exit()
if args.configure:
configure(dir_list=None)
@@ -141,6 +146,7 @@ except Exception as e:
logger.exception(str(e))
if settings is not None:
+
add_log(file_format=formats[str(
settings['fileformat']).upper()], proj_settings=jname_proj, savepath=SAVEPATH, backuppath=BACKUPPATH, job=args.job, proj=args.project,
loc=args.location, time=args.time, start=args.start, end=args.end, message=args.message)