Skip to content

Commit e6ca7d4

Browse files
authored
Update rjj.py
1 parent b5bd3c1 commit e6ca7d4

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

rjj.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# !/usr/bin/env python3
22

3-
__version__="0.9.7"
3+
__version__="0.9.8"
44

55
import argparse, io, os, json, csv, glob, hashlib, warnings, base64, random, math
66
from sklearn.base import BaseEstimator, TransformerMixin
@@ -25,6 +25,43 @@ def list_html_files():
2525
def list_python_files():
2626
return [f for f in os.listdir() if f.endswith('.py')]
2727

28+
def list_data_files():
29+
files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith(('.txt', '.csv', '.json'))]
30+
return files
31+
32+
def data_file_reader(file_name):
33+
if file_name.endswith('.txt'):
34+
with open(file_name, 'r', encoding='utf-8') as f:
35+
print(f.read())
36+
elif file_name.endswith('.csv'):
37+
with open(file_name, 'r', encoding='utf-8') as f:
38+
reader = csv.reader(f)
39+
for row in reader:
40+
print(row)
41+
elif file_name.endswith('.json'):
42+
with open(file_name, 'r', encoding='utf-8') as f:
43+
data = json.load(f)
44+
print(json.dumps(data, indent=4))
45+
else:
46+
print("Unsupported file format.")
47+
48+
def read_data_file():
49+
files = list_data_files()
50+
if not files:
51+
print("No .txt, .csv, or .json files found in the current directory.")
52+
return
53+
print("Available files:")
54+
for i, file in enumerate(files, 1):
55+
print(f"{i}. {file}")
56+
try:
57+
choice = int(input("Select a file by number: ")) - 1
58+
if 0 <= choice < len(files):
59+
data_file_reader(files[choice])
60+
else:
61+
print("Invalid selection.")
62+
except ValueError:
63+
print("Please enter a valid number.")
64+
2865
def py_minifier(file_path):
2966
import ast, pyminify
3067
try:
@@ -3675,6 +3712,7 @@ def __init__():
36753712
subparsers.add_parser('glue', help='glue timestamp')
36763713
subparsers.add_parser('code', help='encode or decode')
36773714
subparsers.add_parser('json', help='join all json up')
3715+
subparsers.add_parser('read', help='read data file')
36783716
subparsers.add_parser('join', help='join it up')
36793717
subparsers.add_parser('home', help='go home')
36803718
args = parser.parse_args()
@@ -3718,6 +3756,8 @@ def __init__():
37183756
joint()
37193757
elif args.subcommand == 'code':
37203758
base64codeHandler()
3759+
elif args.subcommand == 'read':
3760+
read_data_file()
37213761
elif args.subcommand == 'json':
37223762
json_merger()
37233763
elif args.subcommand == 'txt':

0 commit comments

Comments
 (0)