1
1
# !/usr/bin/env python3
2
2
3
- __version__ = "0.9.7 "
3
+ __version__ = "0.9.8 "
4
4
5
5
import argparse , io , os , json , csv , glob , hashlib , warnings , base64 , random , math
6
6
from sklearn .base import BaseEstimator , TransformerMixin
@@ -25,6 +25,43 @@ def list_html_files():
25
25
def list_python_files ():
26
26
return [f for f in os .listdir () if f .endswith ('.py' )]
27
27
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
+
28
65
def py_minifier (file_path ):
29
66
import ast , pyminify
30
67
try :
@@ -3675,6 +3712,7 @@ def __init__():
3675
3712
subparsers .add_parser ('glue' , help = 'glue timestamp' )
3676
3713
subparsers .add_parser ('code' , help = 'encode or decode' )
3677
3714
subparsers .add_parser ('json' , help = 'join all json up' )
3715
+ subparsers .add_parser ('read' , help = 'read data file' )
3678
3716
subparsers .add_parser ('join' , help = 'join it up' )
3679
3717
subparsers .add_parser ('home' , help = 'go home' )
3680
3718
args = parser .parse_args ()
@@ -3718,6 +3756,8 @@ def __init__():
3718
3756
joint ()
3719
3757
elif args .subcommand == 'code' :
3720
3758
base64codeHandler ()
3759
+ elif args .subcommand == 'read' :
3760
+ read_data_file ()
3721
3761
elif args .subcommand == 'json' :
3722
3762
json_merger ()
3723
3763
elif args .subcommand == 'txt' :
0 commit comments