cedbox 0.1.0__tar.gz
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.
- cedbox-0.1.0/LICENSE +21 -0
- cedbox-0.1.0/PKG-INFO +323 -0
- cedbox-0.1.0/README.md +285 -0
- cedbox-0.1.0/cedbox/__init__.py +13 -0
- cedbox-0.1.0/cedbox/easymorse.py +80 -0
- cedbox-0.1.0/cedbox/easywav.py +41 -0
- cedbox-0.1.0/cedbox/inputs.py +120 -0
- cedbox-0.1.0/cedbox/yggdrasil.py +223 -0
- cedbox-0.1.0/cedbox.egg-info/PKG-INFO +323 -0
- cedbox-0.1.0/cedbox.egg-info/SOURCES.txt +15 -0
- cedbox-0.1.0/cedbox.egg-info/dependency_links.txt +1 -0
- cedbox-0.1.0/cedbox.egg-info/requires.txt +4 -0
- cedbox-0.1.0/cedbox.egg-info/top_level.txt +1 -0
- cedbox-0.1.0/pyproject.toml +34 -0
- cedbox-0.1.0/setup.cfg +4 -0
- cedbox-0.1.0/tests/test_inputs.py +181 -0
- cedbox-0.1.0/tests/test_yggdrasil.py +355 -0
cedbox-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cedric Sascha Wagner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cedbox-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cedbox
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python utility package for data handling, input validation, Morse code processing, and audio generation
|
|
5
|
+
Author: CedBox Authors
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Cedric Sascha Wagner
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Classifier: Programming Language :: Python :: 3
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Operating System :: OS Independent
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: pandas>=2.0.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# CedBox
|
|
40
|
+
|
|
41
|
+
CedBox is a Python utility package that provides various tools for data handling, user input validation, Morse code processing, and audio generation.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **Yggdrasil**: A hierarchical tree-like data structure that extends Python's dictionary, with support for:
|
|
46
|
+
- Automatic node creation
|
|
47
|
+
- Loading data from DataFrames and SQL queries
|
|
48
|
+
- Tree visualization
|
|
49
|
+
|
|
50
|
+
- **Input Utilities**: Functions for handling user input with validation and type conversion:
|
|
51
|
+
- String input
|
|
52
|
+
- Integer input with validation
|
|
53
|
+
- Float input with validation
|
|
54
|
+
- Choice selection
|
|
55
|
+
- Boolean (yes/no) input
|
|
56
|
+
- File path input with validation
|
|
57
|
+
- Date input with validation
|
|
58
|
+
- Email input with validation
|
|
59
|
+
|
|
60
|
+
- **Morse Code Processing**: Tools for working with Morse code:
|
|
61
|
+
- Convert text to Morse code
|
|
62
|
+
- Represent Morse code as time units
|
|
63
|
+
- Generate Morse code sequences
|
|
64
|
+
|
|
65
|
+
- **Audio Generation**: Utilities for creating WAV audio files:
|
|
66
|
+
- Generate audio signals from sequences of durations
|
|
67
|
+
- Create Morse code audio signals
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install cedbox
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Usage Examples
|
|
76
|
+
|
|
77
|
+
### Yggdrasil
|
|
78
|
+
|
|
79
|
+
Yggdrasil is a hierarchical tree-like data structure that extends Python's dictionary with additional functionality.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from cedbox import Yggdrasil
|
|
83
|
+
import pandas as pd
|
|
84
|
+
|
|
85
|
+
# Create a new tree
|
|
86
|
+
tree = Yggdrasil()
|
|
87
|
+
|
|
88
|
+
# Add data with automatic node creation
|
|
89
|
+
tree['users']['john']['email'] = 'john@example.com'
|
|
90
|
+
tree['users']['john']['age'] = 30
|
|
91
|
+
tree['users']['jane']['email'] = 'jane@example.com'
|
|
92
|
+
tree['users']['jane']['age'] = 28
|
|
93
|
+
|
|
94
|
+
# Print tree structure
|
|
95
|
+
tree.print_tree()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Output:**
|
|
99
|
+
```
|
|
100
|
+
Yggdrasil
|
|
101
|
+
├── users
|
|
102
|
+
│ ├── john
|
|
103
|
+
│ │ ├── email: john@example.com
|
|
104
|
+
│ │ └── age: 30
|
|
105
|
+
│ └── jane
|
|
106
|
+
│ ├── email: jane@example.com
|
|
107
|
+
│ └── age: 28
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Creating from DataFrame
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
# Create from DataFrame
|
|
114
|
+
df = pd.DataFrame({
|
|
115
|
+
'name': ['John', 'Jane'],
|
|
116
|
+
'email': ['john@example.com', 'jane@example.com'],
|
|
117
|
+
'age': [30, 28]
|
|
118
|
+
})
|
|
119
|
+
tree_from_df = Yggdrasil.from_dataframe(df)
|
|
120
|
+
tree_from_df.print_tree()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Output:**
|
|
124
|
+
```
|
|
125
|
+
Yggdrasil
|
|
126
|
+
├── 0
|
|
127
|
+
│ ├── name: John
|
|
128
|
+
│ ├── email: john@example.com
|
|
129
|
+
│ └── age: 30
|
|
130
|
+
└── 1
|
|
131
|
+
├── name: Jane
|
|
132
|
+
├── email: jane@example.com
|
|
133
|
+
└── age: 28
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Creating from SQL Query
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
import sqlite3
|
|
140
|
+
|
|
141
|
+
# Create a sample database
|
|
142
|
+
conn = sqlite3.connect(':memory:')
|
|
143
|
+
cursor = conn.cursor()
|
|
144
|
+
cursor.execute('CREATE TABLE users (name TEXT, email TEXT, age INTEGER)')
|
|
145
|
+
cursor.execute('INSERT INTO users VALUES ("John", "john@example.com", 30)')
|
|
146
|
+
cursor.execute('INSERT INTO users VALUES ("Jane", "jane@example.com", 28)')
|
|
147
|
+
conn.commit()
|
|
148
|
+
|
|
149
|
+
# Create tree from SQL query
|
|
150
|
+
tree_from_sql = Yggdrasil.from_sql("SELECT * FROM users", conn)
|
|
151
|
+
tree_from_sql.print_tree()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Output:**
|
|
155
|
+
```
|
|
156
|
+
Yggdrasil
|
|
157
|
+
├── 0
|
|
158
|
+
│ ├── name: John
|
|
159
|
+
│ ├── email: john@example.com
|
|
160
|
+
│ └── age: 30
|
|
161
|
+
└── 1
|
|
162
|
+
├── name: Jane
|
|
163
|
+
├── email: jane@example.com
|
|
164
|
+
└── age: 28
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Input Utilities
|
|
168
|
+
|
|
169
|
+
CedBox provides various functions for handling user input with validation and type conversion.
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from cedbox.inputs import (
|
|
173
|
+
string_put, int_put, float_put, choice_put,
|
|
174
|
+
bool_put, file_put, date_put, mail_put
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# String input
|
|
178
|
+
name = string_put("Enter your name: ")
|
|
179
|
+
# User enters: John
|
|
180
|
+
print(f"Hello, {name}!")
|
|
181
|
+
# Output: Hello, John!
|
|
182
|
+
|
|
183
|
+
# Integer input with validation
|
|
184
|
+
age = int_put(
|
|
185
|
+
"Enter your age: ",
|
|
186
|
+
conditions=[lambda x: x > 0, lambda x: x < 120],
|
|
187
|
+
max_times=3,
|
|
188
|
+
default=30
|
|
189
|
+
)
|
|
190
|
+
# User enters: -5
|
|
191
|
+
# Output: -5 is not valid assert lambda x: x > 0
|
|
192
|
+
# User enters: 25
|
|
193
|
+
print(f"You are {age} years old.")
|
|
194
|
+
# Output: You are 25 years old.
|
|
195
|
+
|
|
196
|
+
# Float input with validation
|
|
197
|
+
height = float_put(
|
|
198
|
+
"Enter your height in meters: ",
|
|
199
|
+
conditions=[lambda x: 0.5 < x < 2.5],
|
|
200
|
+
default=1.75
|
|
201
|
+
)
|
|
202
|
+
# User enters: 1.85
|
|
203
|
+
print(f"Your height is {height} meters.")
|
|
204
|
+
# Output: Your height is 1.85 meters.
|
|
205
|
+
|
|
206
|
+
# Choice selection
|
|
207
|
+
color = choice_put("Select a color ", choices=['red', 'green', 'blue'])
|
|
208
|
+
# Output: Select a color (red/green/blue):
|
|
209
|
+
# User enters: yellow
|
|
210
|
+
# Output: yellow is not valid
|
|
211
|
+
# User enters: red
|
|
212
|
+
print(f"You selected {color}.")
|
|
213
|
+
# Output: You selected red.
|
|
214
|
+
|
|
215
|
+
# Boolean input
|
|
216
|
+
confirm = bool_put("Confirm? ")
|
|
217
|
+
# Output: Confirm? (y/n):
|
|
218
|
+
# User enters: y
|
|
219
|
+
print(f"Confirmed: {confirm}")
|
|
220
|
+
# Output: Confirmed: True
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Morse Code Processing
|
|
224
|
+
|
|
225
|
+
The EasyMorse class provides tools for working with Morse code.
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from cedbox import EasyMorse, MORSE_CODE_DICT
|
|
229
|
+
|
|
230
|
+
# Create Morse code from text
|
|
231
|
+
morse = EasyMorse("SOS")
|
|
232
|
+
print(f"Original text: {morse.raw_text}")
|
|
233
|
+
# Output: Original text: SOS
|
|
234
|
+
|
|
235
|
+
print(f"Morse code: {morse.morse_code}")
|
|
236
|
+
# Output: Morse code: ._._.____-_-_-___._._._
|
|
237
|
+
|
|
238
|
+
# View the time sequence (1=dot, 3=dash, -3=pause between symbols)
|
|
239
|
+
print(f"Time sequence: {morse.morse_seq}")
|
|
240
|
+
# Output: Time sequence: [1, 1, 1, -3, 3, 3, 3, -3, 1, 1, 1]
|
|
241
|
+
|
|
242
|
+
# Create with custom prefix (VVV- is a common Morse prefix)
|
|
243
|
+
morse_with_prefix = EasyMorse("HELLO", prefix=True)
|
|
244
|
+
print(f"With prefix: {morse_with_prefix.morse_message}")
|
|
245
|
+
# Output: With prefix: ._._._-___._._._-___._._._-___-_._._._._-_____._._._.___._____._____._._..___._..___._..___---
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Audio Generation
|
|
249
|
+
|
|
250
|
+
The EasyWav class allows you to create WAV audio files from sequences of durations.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from cedbox import EasyMorse, EasyWav
|
|
254
|
+
|
|
255
|
+
# Create Morse code sequence for "SOS"
|
|
256
|
+
morse = EasyMorse("SOS")
|
|
257
|
+
sequence = morse.morse_seq
|
|
258
|
+
print(f"Morse sequence: {sequence}")
|
|
259
|
+
# Output: Morse sequence: [1, 1, 1, -3, 3, 3, 3, -3, 1, 1, 1]
|
|
260
|
+
|
|
261
|
+
# Generate WAV file from sequence
|
|
262
|
+
wav = EasyWav(
|
|
263
|
+
sequence=sequence,
|
|
264
|
+
frequency=800, # 800 Hz tone
|
|
265
|
+
time_unit=100 # 100ms per unit
|
|
266
|
+
)
|
|
267
|
+
wav.save('morse_sos.wav')
|
|
268
|
+
print("Audio file created: morse_sos.wav")
|
|
269
|
+
# Output: Audio file created: morse_sos.wav
|
|
270
|
+
|
|
271
|
+
# Create a more complex audio pattern
|
|
272
|
+
custom_sequence = [1, -1, 3, -1, 1, -3, 5, -5] # Custom pattern of tones and pauses
|
|
273
|
+
wav = EasyWav(
|
|
274
|
+
sequence=custom_sequence,
|
|
275
|
+
frequency=440, # A4 note
|
|
276
|
+
sample_rate=48000 # Higher quality
|
|
277
|
+
)
|
|
278
|
+
wav.save('custom_pattern.wav')
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Complete Example: Morse Code Converter
|
|
282
|
+
|
|
283
|
+
Here's a complete example that combines multiple components to create a Morse code converter:
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
from cedbox import EasyMorse, EasyWav, string_put
|
|
287
|
+
|
|
288
|
+
def morse_converter():
|
|
289
|
+
# Get input text from user
|
|
290
|
+
text = string_put("Enter text to convert to Morse code: ")
|
|
291
|
+
|
|
292
|
+
# Convert to Morse code
|
|
293
|
+
morse = EasyMorse(text, prefix=True)
|
|
294
|
+
|
|
295
|
+
print(f"Text: {morse.raw_text}")
|
|
296
|
+
print(f"Morse code: {morse.morse_code}")
|
|
297
|
+
|
|
298
|
+
# Generate audio file
|
|
299
|
+
wav = EasyWav(
|
|
300
|
+
sequence=morse.morse_seq,
|
|
301
|
+
frequency=800,
|
|
302
|
+
time_unit=80 # Faster speed
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
filename = f"morse_{text.replace(' ', '_')}.wav"
|
|
306
|
+
wav.save(filename)
|
|
307
|
+
print(f"Audio saved to {filename}")
|
|
308
|
+
|
|
309
|
+
return morse, filename
|
|
310
|
+
|
|
311
|
+
# Run the converter
|
|
312
|
+
morse_result, audio_file = morse_converter()
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Dependencies
|
|
316
|
+
|
|
317
|
+
- pandas >= 2.0.0
|
|
318
|
+
- setuptools == 80.9.0
|
|
319
|
+
- pytest (for testing)
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
See the [LICENSE](LICENSE) file for details.
|
cedbox-0.1.0/README.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# CedBox
|
|
2
|
+
|
|
3
|
+
CedBox is a Python utility package that provides various tools for data handling, user input validation, Morse code processing, and audio generation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Yggdrasil**: A hierarchical tree-like data structure that extends Python's dictionary, with support for:
|
|
8
|
+
- Automatic node creation
|
|
9
|
+
- Loading data from DataFrames and SQL queries
|
|
10
|
+
- Tree visualization
|
|
11
|
+
|
|
12
|
+
- **Input Utilities**: Functions for handling user input with validation and type conversion:
|
|
13
|
+
- String input
|
|
14
|
+
- Integer input with validation
|
|
15
|
+
- Float input with validation
|
|
16
|
+
- Choice selection
|
|
17
|
+
- Boolean (yes/no) input
|
|
18
|
+
- File path input with validation
|
|
19
|
+
- Date input with validation
|
|
20
|
+
- Email input with validation
|
|
21
|
+
|
|
22
|
+
- **Morse Code Processing**: Tools for working with Morse code:
|
|
23
|
+
- Convert text to Morse code
|
|
24
|
+
- Represent Morse code as time units
|
|
25
|
+
- Generate Morse code sequences
|
|
26
|
+
|
|
27
|
+
- **Audio Generation**: Utilities for creating WAV audio files:
|
|
28
|
+
- Generate audio signals from sequences of durations
|
|
29
|
+
- Create Morse code audio signals
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install cedbox
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage Examples
|
|
38
|
+
|
|
39
|
+
### Yggdrasil
|
|
40
|
+
|
|
41
|
+
Yggdrasil is a hierarchical tree-like data structure that extends Python's dictionary with additional functionality.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from cedbox import Yggdrasil
|
|
45
|
+
import pandas as pd
|
|
46
|
+
|
|
47
|
+
# Create a new tree
|
|
48
|
+
tree = Yggdrasil()
|
|
49
|
+
|
|
50
|
+
# Add data with automatic node creation
|
|
51
|
+
tree['users']['john']['email'] = 'john@example.com'
|
|
52
|
+
tree['users']['john']['age'] = 30
|
|
53
|
+
tree['users']['jane']['email'] = 'jane@example.com'
|
|
54
|
+
tree['users']['jane']['age'] = 28
|
|
55
|
+
|
|
56
|
+
# Print tree structure
|
|
57
|
+
tree.print_tree()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Output:**
|
|
61
|
+
```
|
|
62
|
+
Yggdrasil
|
|
63
|
+
├── users
|
|
64
|
+
│ ├── john
|
|
65
|
+
│ │ ├── email: john@example.com
|
|
66
|
+
│ │ └── age: 30
|
|
67
|
+
│ └── jane
|
|
68
|
+
│ ├── email: jane@example.com
|
|
69
|
+
│ └── age: 28
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Creating from DataFrame
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
# Create from DataFrame
|
|
76
|
+
df = pd.DataFrame({
|
|
77
|
+
'name': ['John', 'Jane'],
|
|
78
|
+
'email': ['john@example.com', 'jane@example.com'],
|
|
79
|
+
'age': [30, 28]
|
|
80
|
+
})
|
|
81
|
+
tree_from_df = Yggdrasil.from_dataframe(df)
|
|
82
|
+
tree_from_df.print_tree()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Output:**
|
|
86
|
+
```
|
|
87
|
+
Yggdrasil
|
|
88
|
+
├── 0
|
|
89
|
+
│ ├── name: John
|
|
90
|
+
│ ├── email: john@example.com
|
|
91
|
+
│ └── age: 30
|
|
92
|
+
└── 1
|
|
93
|
+
├── name: Jane
|
|
94
|
+
├── email: jane@example.com
|
|
95
|
+
└── age: 28
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Creating from SQL Query
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import sqlite3
|
|
102
|
+
|
|
103
|
+
# Create a sample database
|
|
104
|
+
conn = sqlite3.connect(':memory:')
|
|
105
|
+
cursor = conn.cursor()
|
|
106
|
+
cursor.execute('CREATE TABLE users (name TEXT, email TEXT, age INTEGER)')
|
|
107
|
+
cursor.execute('INSERT INTO users VALUES ("John", "john@example.com", 30)')
|
|
108
|
+
cursor.execute('INSERT INTO users VALUES ("Jane", "jane@example.com", 28)')
|
|
109
|
+
conn.commit()
|
|
110
|
+
|
|
111
|
+
# Create tree from SQL query
|
|
112
|
+
tree_from_sql = Yggdrasil.from_sql("SELECT * FROM users", conn)
|
|
113
|
+
tree_from_sql.print_tree()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Output:**
|
|
117
|
+
```
|
|
118
|
+
Yggdrasil
|
|
119
|
+
├── 0
|
|
120
|
+
│ ├── name: John
|
|
121
|
+
│ ├── email: john@example.com
|
|
122
|
+
│ └── age: 30
|
|
123
|
+
└── 1
|
|
124
|
+
├── name: Jane
|
|
125
|
+
├── email: jane@example.com
|
|
126
|
+
└── age: 28
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Input Utilities
|
|
130
|
+
|
|
131
|
+
CedBox provides various functions for handling user input with validation and type conversion.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from cedbox.inputs import (
|
|
135
|
+
string_put, int_put, float_put, choice_put,
|
|
136
|
+
bool_put, file_put, date_put, mail_put
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# String input
|
|
140
|
+
name = string_put("Enter your name: ")
|
|
141
|
+
# User enters: John
|
|
142
|
+
print(f"Hello, {name}!")
|
|
143
|
+
# Output: Hello, John!
|
|
144
|
+
|
|
145
|
+
# Integer input with validation
|
|
146
|
+
age = int_put(
|
|
147
|
+
"Enter your age: ",
|
|
148
|
+
conditions=[lambda x: x > 0, lambda x: x < 120],
|
|
149
|
+
max_times=3,
|
|
150
|
+
default=30
|
|
151
|
+
)
|
|
152
|
+
# User enters: -5
|
|
153
|
+
# Output: -5 is not valid assert lambda x: x > 0
|
|
154
|
+
# User enters: 25
|
|
155
|
+
print(f"You are {age} years old.")
|
|
156
|
+
# Output: You are 25 years old.
|
|
157
|
+
|
|
158
|
+
# Float input with validation
|
|
159
|
+
height = float_put(
|
|
160
|
+
"Enter your height in meters: ",
|
|
161
|
+
conditions=[lambda x: 0.5 < x < 2.5],
|
|
162
|
+
default=1.75
|
|
163
|
+
)
|
|
164
|
+
# User enters: 1.85
|
|
165
|
+
print(f"Your height is {height} meters.")
|
|
166
|
+
# Output: Your height is 1.85 meters.
|
|
167
|
+
|
|
168
|
+
# Choice selection
|
|
169
|
+
color = choice_put("Select a color ", choices=['red', 'green', 'blue'])
|
|
170
|
+
# Output: Select a color (red/green/blue):
|
|
171
|
+
# User enters: yellow
|
|
172
|
+
# Output: yellow is not valid
|
|
173
|
+
# User enters: red
|
|
174
|
+
print(f"You selected {color}.")
|
|
175
|
+
# Output: You selected red.
|
|
176
|
+
|
|
177
|
+
# Boolean input
|
|
178
|
+
confirm = bool_put("Confirm? ")
|
|
179
|
+
# Output: Confirm? (y/n):
|
|
180
|
+
# User enters: y
|
|
181
|
+
print(f"Confirmed: {confirm}")
|
|
182
|
+
# Output: Confirmed: True
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Morse Code Processing
|
|
186
|
+
|
|
187
|
+
The EasyMorse class provides tools for working with Morse code.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from cedbox import EasyMorse, MORSE_CODE_DICT
|
|
191
|
+
|
|
192
|
+
# Create Morse code from text
|
|
193
|
+
morse = EasyMorse("SOS")
|
|
194
|
+
print(f"Original text: {morse.raw_text}")
|
|
195
|
+
# Output: Original text: SOS
|
|
196
|
+
|
|
197
|
+
print(f"Morse code: {morse.morse_code}")
|
|
198
|
+
# Output: Morse code: ._._.____-_-_-___._._._
|
|
199
|
+
|
|
200
|
+
# View the time sequence (1=dot, 3=dash, -3=pause between symbols)
|
|
201
|
+
print(f"Time sequence: {morse.morse_seq}")
|
|
202
|
+
# Output: Time sequence: [1, 1, 1, -3, 3, 3, 3, -3, 1, 1, 1]
|
|
203
|
+
|
|
204
|
+
# Create with custom prefix (VVV- is a common Morse prefix)
|
|
205
|
+
morse_with_prefix = EasyMorse("HELLO", prefix=True)
|
|
206
|
+
print(f"With prefix: {morse_with_prefix.morse_message}")
|
|
207
|
+
# Output: With prefix: ._._._-___._._._-___._._._-___-_._._._._-_____._._._.___._____._____._._..___._..___._..___---
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Audio Generation
|
|
211
|
+
|
|
212
|
+
The EasyWav class allows you to create WAV audio files from sequences of durations.
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from cedbox import EasyMorse, EasyWav
|
|
216
|
+
|
|
217
|
+
# Create Morse code sequence for "SOS"
|
|
218
|
+
morse = EasyMorse("SOS")
|
|
219
|
+
sequence = morse.morse_seq
|
|
220
|
+
print(f"Morse sequence: {sequence}")
|
|
221
|
+
# Output: Morse sequence: [1, 1, 1, -3, 3, 3, 3, -3, 1, 1, 1]
|
|
222
|
+
|
|
223
|
+
# Generate WAV file from sequence
|
|
224
|
+
wav = EasyWav(
|
|
225
|
+
sequence=sequence,
|
|
226
|
+
frequency=800, # 800 Hz tone
|
|
227
|
+
time_unit=100 # 100ms per unit
|
|
228
|
+
)
|
|
229
|
+
wav.save('morse_sos.wav')
|
|
230
|
+
print("Audio file created: morse_sos.wav")
|
|
231
|
+
# Output: Audio file created: morse_sos.wav
|
|
232
|
+
|
|
233
|
+
# Create a more complex audio pattern
|
|
234
|
+
custom_sequence = [1, -1, 3, -1, 1, -3, 5, -5] # Custom pattern of tones and pauses
|
|
235
|
+
wav = EasyWav(
|
|
236
|
+
sequence=custom_sequence,
|
|
237
|
+
frequency=440, # A4 note
|
|
238
|
+
sample_rate=48000 # Higher quality
|
|
239
|
+
)
|
|
240
|
+
wav.save('custom_pattern.wav')
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Complete Example: Morse Code Converter
|
|
244
|
+
|
|
245
|
+
Here's a complete example that combines multiple components to create a Morse code converter:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from cedbox import EasyMorse, EasyWav, string_put
|
|
249
|
+
|
|
250
|
+
def morse_converter():
|
|
251
|
+
# Get input text from user
|
|
252
|
+
text = string_put("Enter text to convert to Morse code: ")
|
|
253
|
+
|
|
254
|
+
# Convert to Morse code
|
|
255
|
+
morse = EasyMorse(text, prefix=True)
|
|
256
|
+
|
|
257
|
+
print(f"Text: {morse.raw_text}")
|
|
258
|
+
print(f"Morse code: {morse.morse_code}")
|
|
259
|
+
|
|
260
|
+
# Generate audio file
|
|
261
|
+
wav = EasyWav(
|
|
262
|
+
sequence=morse.morse_seq,
|
|
263
|
+
frequency=800,
|
|
264
|
+
time_unit=80 # Faster speed
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
filename = f"morse_{text.replace(' ', '_')}.wav"
|
|
268
|
+
wav.save(filename)
|
|
269
|
+
print(f"Audio saved to {filename}")
|
|
270
|
+
|
|
271
|
+
return morse, filename
|
|
272
|
+
|
|
273
|
+
# Run the converter
|
|
274
|
+
morse_result, audio_file = morse_converter()
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Dependencies
|
|
278
|
+
|
|
279
|
+
- pandas >= 2.0.0
|
|
280
|
+
- setuptools == 80.9.0
|
|
281
|
+
- pytest (for testing)
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CedBox - A Python utility package for data handling, input validation, Morse code processing, and audio generation.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from cedbox.yggdrasil import Yggdrasil
|
|
6
|
+
from cedbox.inputs import (
|
|
7
|
+
string_put, int_put, float_put, choice_put,
|
|
8
|
+
bool_put, file_put, date_put, mail_put
|
|
9
|
+
)
|
|
10
|
+
from cedbox.easymorse import EasyMorse, MORSE_CODE_DICT
|
|
11
|
+
from cedbox.easywav import EasyWav
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|