Created
February 9, 2023 16:08
-
-
Save MattJermyWright/db28c2e7bffec500020387174c358cc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typer | |
from loguru import logger as log | |
import sys | |
import os | |
from os.path import exists | |
# Log Setup | |
log.remove() | |
log.add(sys.stderr, level="INFO") | |
# CLI Setup | |
app = typer.Typer() | |
DELIM = chr(29) | |
NEW_DELIM = '\t' | |
ENCODING = 'utf-8' | |
def decode_line(input_line:str): | |
return NEW_DELIM.join( [i for i in input_line.split(DELIM)]) | |
@log.catch | |
@app.command() | |
def do_function1(input_file:str): ## Adjust function name for better information | |
input_full_filename = os.path.abspath(input_file) | |
if exists(input_full_filename): | |
with open(input_full_filename, "r", encoding=ENCODING) as filePointer: | |
with open(input_full_filename + '.out', "w", encoding=ENCODING) as filePointerOut: | |
log.info(f"Found filename: {input_full_filename}") | |
cnt = 0 | |
for line in filePointer: | |
cnt += 1 | |
filePointerOut.write(decode_line(line) + "\n") | |
log.success(f"File read: {cnt} lines found") | |
else: | |
log.error(f"File does not exist: {input_full_filename}") | |
# Execute CLI for all @app.command calls | |
if __name__ == "__main__": | |
app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment