rgwfuncs 0.0.103__py3-none-any.whl → 0.0.107__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rgwfuncs/__init__.py +1 -1
- rgwfuncs/str_lib.py +170 -0
- {rgwfuncs-0.0.103.dist-info → rgwfuncs-0.0.107.dist-info}/METADATA +2 -1
- rgwfuncs-0.0.107.dist-info/RECORD +11 -0
- rgwfuncs-0.0.103.dist-info/RECORD +0 -11
- {rgwfuncs-0.0.103.dist-info → rgwfuncs-0.0.107.dist-info}/WHEEL +0 -0
- {rgwfuncs-0.0.103.dist-info → rgwfuncs-0.0.107.dist-info}/entry_points.txt +0 -0
- {rgwfuncs-0.0.103.dist-info → rgwfuncs-0.0.107.dist-info}/licenses/LICENSE +0 -0
- {rgwfuncs-0.0.103.dist-info → rgwfuncs-0.0.107.dist-info}/top_level.txt +0 -0
rgwfuncs/__init__.py
CHANGED
@@ -4,4 +4,4 @@
|
|
4
4
|
from .df_lib import append_columns, append_percentile_classification_column, append_ranged_classification_column, append_ranged_date_classification_column, append_rows, append_xgb_labels, append_xgb_logistic_regression_predictions, append_xgb_regression_predictions, bag_union_join, bottom_n_unique_values, cascade_sort, delete_rows, drop_duplicates, drop_duplicates_retain_first, drop_duplicates_retain_last, filter_dataframe, filter_indian_mobiles, first_n_rows, from_raw_data, insert_dataframe_in_sqlite_database, last_n_rows, left_join, limit_dataframe, load_data_from_path, load_data_from_query, load_data_from_sqlite_path, load_fresh_data_or_pull_from_cache, mask_against_dataframe, mask_against_dataframe_converse, numeric_clean, order_columns, print_correlation, print_dataframe, print_memory_usage, print_n_frequency_cascading, print_n_frequency_linear, rename_columns, retain_columns, right_join, send_data_to_email, send_data_to_slack, send_dataframe_via_telegram, sync_dataframe_to_sqlite_database, top_n_unique_values, union_join, update_rows
|
5
5
|
from .interactive_shell_lib import interactive_shell
|
6
6
|
from .docs_lib import docs
|
7
|
-
from .str_lib import send_telegram_message
|
7
|
+
from .str_lib import heading, send_telegram_message, sub_heading, title
|
rgwfuncs/str_lib.py
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
+
import sys
|
2
|
+
import time
|
1
3
|
import os
|
2
4
|
import json
|
3
5
|
import requests
|
4
6
|
from typing import Tuple, Optional, Union, Dict
|
7
|
+
from collections import defaultdict
|
5
8
|
import warnings
|
9
|
+
from pyfiglet import Figlet
|
10
|
+
from datetime import datetime
|
6
11
|
|
7
12
|
# Suppress all FutureWarnings
|
8
13
|
warnings.filterwarnings("ignore", category=FutureWarning)
|
9
14
|
|
15
|
+
# Module-level variables
|
16
|
+
_PRINT_HEADING_CURRENT_CALL = 0
|
17
|
+
_PRINT_SUBHEADING_COUNTS = defaultdict(int) # Tracks sub-headings per heading
|
18
|
+
_CURRENT_HEADING_NUMBER = 0
|
10
19
|
|
11
20
|
def send_telegram_message(preset_name: str, message: str, config: Optional[Union[str, dict]] = None) -> None:
|
12
21
|
"""
|
@@ -104,3 +113,164 @@ def send_telegram_message(preset_name: str, message: str, config: Optional[Union
|
|
104
113
|
# Send the message
|
105
114
|
response = requests.post(url, json=payload)
|
106
115
|
response.raise_for_status()
|
116
|
+
|
117
|
+
def title(text: str, font: str = "slant", typing_speed: float = 0.005) -> None:
|
118
|
+
"""
|
119
|
+
Print text as ASCII art with a typewriter effect using the specified font (default: slant),
|
120
|
+
indented by 4 spaces. All output, including errors and separators, is printed with the
|
121
|
+
typewriter effect within this function.
|
122
|
+
|
123
|
+
Args:
|
124
|
+
text (str): The text to convert to ASCII art.
|
125
|
+
font (str, optional): The pyfiglet font to use. Defaults to "slant".
|
126
|
+
typing_speed (float, optional): Delay between printing each character in seconds.
|
127
|
+
Defaults to 0.005.
|
128
|
+
|
129
|
+
Raises:
|
130
|
+
ValueError: If the specified font is invalid or unavailable.
|
131
|
+
RuntimeError: If there is an error generating the ASCII art.
|
132
|
+
"""
|
133
|
+
# ANSI color codes
|
134
|
+
heading_color = '\033[92m' # Bright green for headings
|
135
|
+
reset_color = '\033[0m' # Reset to default
|
136
|
+
|
137
|
+
try:
|
138
|
+
# Initialize Figlet with the specified font
|
139
|
+
figlet = Figlet(font=font)
|
140
|
+
# Generate ASCII art
|
141
|
+
ascii_art = figlet.renderText(text)
|
142
|
+
# Indent each line by 4 spaces
|
143
|
+
indented_ascii_art = '\n'.join(' ' + line for line in ascii_art.splitlines())
|
144
|
+
|
145
|
+
# Print ASCII art with typewriter effect
|
146
|
+
print(heading_color, end='')
|
147
|
+
for char in indented_ascii_art + '\n':
|
148
|
+
print(char, end='', flush=True)
|
149
|
+
if char != '\n': # Don't delay on newlines
|
150
|
+
time.sleep(typing_speed)
|
151
|
+
print(reset_color, end='')
|
152
|
+
|
153
|
+
# Print separator line with typewriter effect
|
154
|
+
print(heading_color, end='')
|
155
|
+
for char in '=' * 79 + '\n':
|
156
|
+
print(char, end='', flush=True)
|
157
|
+
if char != '\n':
|
158
|
+
time.sleep(typing_speed)
|
159
|
+
print(reset_color, end='')
|
160
|
+
|
161
|
+
except Exception as e:
|
162
|
+
error_msg = ''
|
163
|
+
if "font" in str(e).lower():
|
164
|
+
error_msg = f"Invalid or unavailable font: {font}. Ensure the font is supported by pyfiglet.\n"
|
165
|
+
print(reset_color, end='')
|
166
|
+
for char in error_msg:
|
167
|
+
print(char, end='', flush=True)
|
168
|
+
if char != '\n':
|
169
|
+
time.sleep(typing_speed)
|
170
|
+
raise ValueError(error_msg)
|
171
|
+
error_msg = f"Error generating ASCII art for \"{text}\" with font {font}: {e}\n"
|
172
|
+
print(reset_color, end='')
|
173
|
+
for char in error_msg:
|
174
|
+
print(char, end='', flush=True)
|
175
|
+
if char != '\n':
|
176
|
+
time.sleep(typing_speed)
|
177
|
+
raise RuntimeError(error_msg)
|
178
|
+
|
179
|
+
def heading(text: str, typing_speed: float = 0.002) -> None:
|
180
|
+
"""
|
181
|
+
Print a heading with the specified text in uppercase,
|
182
|
+
formatted as '[current_call] TEXT' with a timestamp and typewriter effect.
|
183
|
+
Ensures the formatted heading is <= 50 characters and total line is 79 characters.
|
184
|
+
Adds empty lines before and after the heading.
|
185
|
+
|
186
|
+
Args:
|
187
|
+
text (str): The heading text to print.
|
188
|
+
typing_speed (float, optional): Delay between printing each character in seconds.
|
189
|
+
Defaults to 0.005.
|
190
|
+
"""
|
191
|
+
global _PRINT_HEADING_CURRENT_CALL, _CURRENT_HEADING_NUMBER, _PRINT_SUBHEADING_COUNTS
|
192
|
+
|
193
|
+
# Increment heading call
|
194
|
+
_PRINT_HEADING_CURRENT_CALL += 1
|
195
|
+
_CURRENT_HEADING_NUMBER = _PRINT_HEADING_CURRENT_CALL
|
196
|
+
_PRINT_SUBHEADING_COUNTS[_CURRENT_HEADING_NUMBER] = 0 # Reset sub-heading count
|
197
|
+
|
198
|
+
# ANSI color codes
|
199
|
+
color = '\033[92m' # Bright green for headings
|
200
|
+
reset_color = '\033[0m'
|
201
|
+
|
202
|
+
# Format heading
|
203
|
+
prefix = f"[{_PRINT_HEADING_CURRENT_CALL}] "
|
204
|
+
max_text_length = 50 - len(prefix)
|
205
|
+
formatted_text = text.upper()[:max_text_length]
|
206
|
+
heading = f"{prefix}{formatted_text}"
|
207
|
+
|
208
|
+
# Get timestamp
|
209
|
+
timestamp = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}]"
|
210
|
+
|
211
|
+
# Calculate padding
|
212
|
+
padding_length = 79 - len(heading) - 1 - len(timestamp) - 1 # Spaces before padding and timestamp
|
213
|
+
padding = '=' * padding_length if padding_length > 0 else ''
|
214
|
+
full_line = f"{heading} {padding} {timestamp}"
|
215
|
+
|
216
|
+
# Print with line breaks and typewriter effect
|
217
|
+
print() # Empty line before
|
218
|
+
print(color, end='')
|
219
|
+
for char in full_line + '\n':
|
220
|
+
print(char, end='', flush=True)
|
221
|
+
if char != '\n':
|
222
|
+
time.sleep(typing_speed)
|
223
|
+
print(reset_color, end='')
|
224
|
+
print() # Empty line after
|
225
|
+
|
226
|
+
def sub_heading(text: str, typing_speed: float = 0.002) -> None:
|
227
|
+
"""
|
228
|
+
Print a sub-heading under the most recent heading, formatted as
|
229
|
+
'[heading_num.sub_heading_num] TEXT' with a timestamp and typewriter effect.
|
230
|
+
Ensures the formatted sub-heading is <= 50 characters and total line is 79 characters.
|
231
|
+
Adds empty lines before and after the sub-heading.
|
232
|
+
|
233
|
+
Args:
|
234
|
+
text (str): The sub-heading text to print.
|
235
|
+
typing_speed (float, optional): Delay between printing each character in seconds.
|
236
|
+
Defaults to 0.005.
|
237
|
+
|
238
|
+
Raises:
|
239
|
+
ValueError: If no heading has been called.
|
240
|
+
"""
|
241
|
+
global _PRINT_SUBHEADING_COUNTS, _CURRENT_HEADING_NUMBER
|
242
|
+
|
243
|
+
if _CURRENT_HEADING_NUMBER == 0:
|
244
|
+
raise ValueError("No heading called before sub_heading.")
|
245
|
+
|
246
|
+
# Increment sub-heading count
|
247
|
+
_PRINT_SUBHEADING_COUNTS[_CURRENT_HEADING_NUMBER] += 1
|
248
|
+
current_sub = _PRINT_SUBHEADING_COUNTS[_CURRENT_HEADING_NUMBER]
|
249
|
+
|
250
|
+
# ANSI color codes
|
251
|
+
color = '\033[92m' # Bright green for sub-headings
|
252
|
+
reset_color = '\033[0m'
|
253
|
+
|
254
|
+
# Format sub-heading
|
255
|
+
prefix = f"[{_CURRENT_HEADING_NUMBER}.{current_sub}] "
|
256
|
+
max_text_length = 50 - len(prefix)
|
257
|
+
formatted_text = text.lower()[:max_text_length]
|
258
|
+
sub_heading = f"{prefix}{formatted_text}"
|
259
|
+
|
260
|
+
# Get timestamp
|
261
|
+
timestamp = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}]"
|
262
|
+
|
263
|
+
# Calculate padding
|
264
|
+
padding_length = 79 - len(sub_heading) - 1 - len(timestamp) - 1 # Spaces before padding and timestamp
|
265
|
+
padding = '-' * padding_length if padding_length > 0 else ''
|
266
|
+
full_line = f"{sub_heading} {padding} {timestamp}"
|
267
|
+
|
268
|
+
# Print with line breaks and typewriter effect
|
269
|
+
print() # Empty line before
|
270
|
+
print(color, end='')
|
271
|
+
for char in full_line + '\n':
|
272
|
+
print(char, end='', flush=True)
|
273
|
+
if char != '\n':
|
274
|
+
time.sleep(typing_speed)
|
275
|
+
print(reset_color, end='')
|
276
|
+
print() # Empty line after
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: rgwfuncs
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.107
|
4
4
|
Summary: A functional programming paradigm for mathematical modelling and data science
|
5
5
|
Home-page: https://github.com/ryangerardwilson/rgwfuncs
|
6
6
|
Author: Ryan Gerard Wilson
|
@@ -24,6 +24,7 @@ Requires-Dist: requests
|
|
24
24
|
Requires-Dist: slack-sdk
|
25
25
|
Requires-Dist: google-api-python-client
|
26
26
|
Requires-Dist: boto3
|
27
|
+
Requires-Dist: pyfiglet
|
27
28
|
Dynamic: license-file
|
28
29
|
|
29
30
|
# RGWFUNCS
|
@@ -0,0 +1,11 @@
|
|
1
|
+
rgwfuncs/__init__.py,sha256=XIbMHeEimBLNcX2PK7uQGquG-eAYXsetVEJrlBZIH5U,1295
|
2
|
+
rgwfuncs/df_lib.py,sha256=3foomRHlunCpf_accTcqfdgwDmSPIVkVCnlWJ4ag4XQ,76947
|
3
|
+
rgwfuncs/docs_lib.py,sha256=i63NzX-V8cGhikYdtkRGAEe2VcuwpXxDUyTRa9xI7l8,1972
|
4
|
+
rgwfuncs/interactive_shell_lib.py,sha256=YeJBW9YgH5Nv77ONdOyIKFgtf0ItXStdlKGN9GGf8bU,4228
|
5
|
+
rgwfuncs/str_lib.py,sha256=xjdD-NJcb5YPKIDnJFItXIUXlTmjX1Kg3lci8eqvfQs,11391
|
6
|
+
rgwfuncs-0.0.107.dist-info/licenses/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
|
7
|
+
rgwfuncs-0.0.107.dist-info/METADATA,sha256=1yKapK7_SsGrpRCAqxnDap4zpoUQ9cz8DbUTLMcCx7g,42972
|
8
|
+
rgwfuncs-0.0.107.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
+
rgwfuncs-0.0.107.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
10
|
+
rgwfuncs-0.0.107.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
11
|
+
rgwfuncs-0.0.107.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
rgwfuncs/__init__.py,sha256=ULY2H_0hLkp4sEdeZnlSJujb6-nZIeZGrBUWeQTZX4A,1266
|
2
|
-
rgwfuncs/df_lib.py,sha256=3foomRHlunCpf_accTcqfdgwDmSPIVkVCnlWJ4ag4XQ,76947
|
3
|
-
rgwfuncs/docs_lib.py,sha256=i63NzX-V8cGhikYdtkRGAEe2VcuwpXxDUyTRa9xI7l8,1972
|
4
|
-
rgwfuncs/interactive_shell_lib.py,sha256=YeJBW9YgH5Nv77ONdOyIKFgtf0ItXStdlKGN9GGf8bU,4228
|
5
|
-
rgwfuncs/str_lib.py,sha256=qpt7jPbQ2Feu88zt3_7L8w5jMsBGacBS74Sa5om4VLE,4814
|
6
|
-
rgwfuncs-0.0.103.dist-info/licenses/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
|
7
|
-
rgwfuncs-0.0.103.dist-info/METADATA,sha256=fR6-WFPr2FcT6vDJguK2U_wGh0qY0nMjnjZdt6tkJHU,42948
|
8
|
-
rgwfuncs-0.0.103.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
-
rgwfuncs-0.0.103.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
|
10
|
-
rgwfuncs-0.0.103.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
|
11
|
-
rgwfuncs-0.0.103.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|