Skip to content

Commit 6fcba5f

Browse files
committed
Add suffix to sequence in filename
1 parent c124853 commit 6fcba5f

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/main/helpers/package_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self):
4040
'site_solution': '',
4141
'notes': '',
4242
'nb': '',
43+
'seq_full': '',
4344
'filename': '',
4445
'lastline': '\n',
4546
},

src/main/main.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def initialize_runs(handler: PackageHandler, today: datetime) -> int:
209209
return 1
210210

211211

212-
def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
212+
def open_runs_seq(handler: PackageHandler, today: datetime) -> tuple[str, str]:
213213
"""
214214
Generates a sequence identifier for each entry in the Index table and solution
215215
filename prefix.
@@ -219,15 +219,18 @@ def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
219219
today (datetime): Current timestamp for sequence generation
220220
221221
Returns:
222-
str: Sequence identifier either as a 3-digit number or date string (YYYY-MM-DD)
222+
tuple[str, str]: Tuple containing (sequence_id, full_sequence_id) where:
223+
- sequence_id: Either a 3-digit number or date string (YYYY‑MM‑DD)
224+
- full_sequence_id: sequence_id with suffix (e.g. "001_01" or "2025‑01‑31_01")
223225
224226
Raises:
225227
ValueError: If seq_notation_loc is not 0 or 1
226228
227229
Note:
228230
Uses seq_notation_loc to determine sequence format:
229231
- 0: Three digit sequence (e.g. "001")
230-
- 1: Date format (e.g. "2025‑01‑31")
232+
- 1: Date format using Unicode non-breaking hyphens U+2011 (e.g. "2025‑01‑31")
233+
231234
"""
232235
seq_start_loc = handler.get_value('config_base', 'seq_start_loc')
233236
seq_notation_loc = handler.get_value('config_base', 'seq_notation_loc')
@@ -242,11 +245,12 @@ def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
242245

243246
file_last = files[-1]
244247

248+
# Handle sequence partials
245249
if seq_notation_loc == 0:
246250

247251
seq_last = int(file_last[:3])
248-
249-
# seq_next = seq_last + 1
252+
253+
seq_last_suffix = int(file_last[4:6])
250254

251255
seq_actual = datetime.strptime(seq_start_loc, f'%Y{hyphen}%m{hyphen}%d')
252256
seq_actual = seq_actual.date()
@@ -259,7 +263,7 @@ def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
259263
seq_last = datetime.strptime(file_last[:10], f'%Y{hyphen}%m{hyphen}%d')
260264
seq_last = seq_last.date()
261265

262-
# seq_next = seq_last + timedelta(days=1)
266+
seq_last_suffix = int(file_last[11:13])
263267

264268
seq_actual = datetime.now().date()
265269

@@ -269,10 +273,16 @@ def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
269273

270274
raise ValueError('Invalid configuration: TODO')
271275

276+
# Handle full sequence
272277
if seq_last == seq_actual:
278+
seq_suffix = seq_last_suffix + 1
279+
seq_suffix = f'{seq_suffix:02d}'
280+
seq_full = f'{seq}_{seq_suffix}'
273281
print('Note: You have submitted more than 1 entry today.')
282+
274283
elif seq_last < seq_actual:
275-
pass
284+
seq_full = f'{seq}_01'
285+
276286
else:
277287
print('Note: Invalid sequence. Processing not terminated.')
278288

@@ -281,19 +291,21 @@ def open_runs_seq(handler: PackageHandler, today: datetime) -> str:
281291
if seq_notation_loc == 0:
282292

283293
seq = '001'
294+
seq_full = '001_01'
284295

285296
elif seq_notation_loc == 1:
286297

287298
seq = today.strftime(f'%Y{hyphen}%m{hyphen}%d')
299+
seq_full = today.strftime(f'%Y{hyphen}%m{hyphen}%d_01')
288300

289301
else:
290302

291303
raise ValueError('Invalid configuration: TODO')
292304

293-
return seq
305+
return seq, seq_full
294306

295307

296-
def open_runs_file(title: str, seq: str) -> str:
308+
def open_runs_file(title: str, seq_full: str) -> str:
297309
"""
298310
Creates a standardized filename from title and sequence identifier.
299311
@@ -308,13 +320,13 @@ def open_runs_file(title: str, seq: str) -> str:
308320
filename = re.sub(r'[^a-z0-9\s-]', '', filename)
309321
filename = filename.replace(' ', '_')
310322
filename = filename.replace('-', '_')
311-
filename = f'{seq}_{filename.strip()}.md'
323+
filename = f'{seq_full}_{filename.strip()}.md'
312324

313325

314326
return filename
315327

316328

317-
def open_runs_dicts(handler: PackageHandler, seq: str, new_package: dict, filename: str) -> int:
329+
def open_runs_dicts(handler: PackageHandler, seq: str, seq_full: str, new_package: dict, filename: str) -> int:
318330
"""
319331
Updates PackageHandler dictionaries.
320332
@@ -343,6 +355,7 @@ def open_runs_dicts(handler: PackageHandler, seq: str, new_package: dict, filena
343355
handler.update_value('package', 'site_solution', new_package["site_solution"])
344356
handler.update_value('package', 'notes', new_package["notes"])
345357
handler.update_value('package', 'nb', new_package["nb"])
358+
handler.update_value('package', 'seq_full', seq_full)
346359
handler.update_value('package', 'filename', filename)
347360

348361
# Update entry_data
@@ -408,13 +421,13 @@ def open_runs(handler: PackageHandler, package_list: list[str], today: datetime)
408421
}
409422

410423
# Create sequence
411-
seq = open_runs_seq(handler, today)
424+
seq, seq_full = open_runs_seq(handler, today)
412425

413426
# Create filename
414-
filename = open_runs_file(new_package['title'], seq)
427+
filename = open_runs_file(new_package['title'], seq_full)
415428

416429
# Update PackageHandler dicts
417-
results = open_runs_dicts(handler, seq, new_package, filename)
430+
results = open_runs_dicts(handler, seq, seq_full, new_package, filename)
418431

419432

420433
return results

src/main/templates/solution.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [ ] Everyday \#{{ day }}
1+
# [ ] Everyday \#{{ seq_full }}
22

33
## {{ title }}
44

0 commit comments

Comments
 (0)