🔨 new comic script
This commit is contained in:
56
scripts/add_comic.py
Executable file
56
scripts/add_comic.py
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Script to add a new comic entry to comics_data.py with reasonable defaults
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# Add parent directory to path so we can import comics_data
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
from comics_data import COMICS
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Add a new comic entry with defaults"""
|
||||||
|
# Get next number
|
||||||
|
number = max(comic['number'] for comic in COMICS) + 1 if COMICS else 1
|
||||||
|
|
||||||
|
# Create entry with defaults
|
||||||
|
comic = {
|
||||||
|
'number': number,
|
||||||
|
'filename': f'comic-{number:03d}.png',
|
||||||
|
'date': datetime.now().strftime('%Y-%m-%d'),
|
||||||
|
'alt_text': f'Comic #{number}',
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get path to comics_data.py
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
parent_dir = os.path.dirname(script_dir)
|
||||||
|
comics_file = os.path.join(parent_dir, 'comics_data.py')
|
||||||
|
|
||||||
|
# Read file
|
||||||
|
with open(comics_file, 'r') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
# Format new entry
|
||||||
|
entry_str = f""" {{
|
||||||
|
'number': {comic['number']},
|
||||||
|
'filename': {repr(comic['filename'])},
|
||||||
|
'date': {repr(comic['date'])},
|
||||||
|
'alt_text': {repr(comic['alt_text'])}
|
||||||
|
}}"""
|
||||||
|
|
||||||
|
# Insert before closing bracket
|
||||||
|
insert_pos = content.rfind(']')
|
||||||
|
new_content = content[:insert_pos] + entry_str + ",\n" + content[insert_pos:]
|
||||||
|
|
||||||
|
# Write back
|
||||||
|
with open(comics_file, 'w') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
|
||||||
|
print(f"Added comic #{number}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user