Initializes project with GEDCOM to Markdown converter
Sets up core functionality for converting genealogy GEDCOM files to Obsidian markdown notes Implements key components: - GEDCOM parsing and individual data extraction - Markdown note generation with rich metadata - Index file creation - Comprehensive test suite for robust functionality Adds initial project structure, configuration, and essential modules for genealogy data conversion
This commit is contained in:
14 files changed
+2313
-275
No files matched your search
+49
-42
@@ -26,8 +26,8 @@ def setup_logging(verbose: bool = False):
|
||||
level = logging.DEBUG if verbose else logging.INFO
|
||||
logging.basicConfig(
|
||||
level=level,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
|
||||
|
||||
@@ -49,27 +49,29 @@ def extract_gedzip(zip_path: Path, temp_dir: Path) -> Tuple[Path, Optional[Path]
|
||||
logger.info(f"Extracting ZIP archive: {zip_path}")
|
||||
|
||||
# Extract the ZIP file
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
||||
zip_ref.extractall(temp_dir)
|
||||
|
||||
logger.info(f"Extracted to: {temp_dir}")
|
||||
|
||||
# Find the GEDCOM file (should have .ged extension)
|
||||
gedcom_files = list(temp_dir.glob('**/*.ged'))
|
||||
gedcom_files = list(temp_dir.glob("**/*.ged"))
|
||||
|
||||
if not gedcom_files:
|
||||
raise ValueError("No GEDCOM (.ged) file found in the ZIP archive")
|
||||
|
||||
if len(gedcom_files) > 1:
|
||||
logger.warning(f"Found {len(gedcom_files)} GEDCOM files, using first: {gedcom_files[0]}")
|
||||
logger.warning(
|
||||
f"Found {len(gedcom_files)} GEDCOM files, using first: {gedcom_files[0]}"
|
||||
)
|
||||
|
||||
gedcom_file = gedcom_files[0]
|
||||
logger.info(f"Found GEDCOM file: {gedcom_file.name}")
|
||||
|
||||
# Find media directory (look for common image extensions)
|
||||
media_dir = None
|
||||
for ext in ['*.jpg', '*.jpeg', '*.png', '*.gif', '*.bmp']:
|
||||
media_files = list(temp_dir.glob(f'**/{ext}'))
|
||||
for ext in ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.bmp"]:
|
||||
media_files = list(temp_dir.glob(f"**/{ext}"))
|
||||
if media_files:
|
||||
# Get the common parent directory of media files
|
||||
media_dir = media_files[0].parent
|
||||
@@ -84,7 +86,7 @@ def convert_gedcom_to_markdown(
|
||||
output_dir: Path,
|
||||
create_index: bool = True,
|
||||
media_dir: Optional[Path] = None,
|
||||
use_flat_structure: bool = False
|
||||
use_flat_structure: bool = False,
|
||||
) -> int:
|
||||
"""
|
||||
Convert a GEDCOM file to markdown notes.
|
||||
@@ -107,14 +109,14 @@ def convert_gedcom_to_markdown(
|
||||
people_dir = output_dir
|
||||
media_output_dir = output_dir
|
||||
stories_dir = output_dir
|
||||
media_subdir_name = ''
|
||||
stories_subdir_name = ''
|
||||
media_subdir_name = ""
|
||||
stories_subdir_name = ""
|
||||
else:
|
||||
people_dir = output_dir / 'people'
|
||||
media_output_dir = output_dir / 'media'
|
||||
stories_dir = output_dir / 'stories'
|
||||
media_subdir_name = 'media'
|
||||
stories_subdir_name = 'stories'
|
||||
people_dir = output_dir / "people"
|
||||
media_output_dir = output_dir / "media"
|
||||
stories_dir = output_dir / "stories"
|
||||
media_subdir_name = "media"
|
||||
stories_subdir_name = "stories"
|
||||
|
||||
# Create subdirectories
|
||||
people_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -134,9 +136,7 @@ def convert_gedcom_to_markdown(
|
||||
return 1
|
||||
|
||||
# Wrap individuals in our data model
|
||||
individuals = [
|
||||
Individual(elem, parser) for elem in individual_elements
|
||||
]
|
||||
individuals = [Individual(elem, parser) for elem in individual_elements]
|
||||
|
||||
# Generate markdown notes
|
||||
logger.info(f"Generating markdown notes in: {people_dir}")
|
||||
@@ -144,7 +144,7 @@ def convert_gedcom_to_markdown(
|
||||
people_dir,
|
||||
media_subdir=media_subdir_name,
|
||||
stories_subdir=stories_subdir_name,
|
||||
stories_dir=stories_dir
|
||||
stories_dir=stories_dir,
|
||||
)
|
||||
created_files = generator.generate_all(individuals)
|
||||
logger.info(f"Created {len(created_files)} markdown files")
|
||||
@@ -153,7 +153,16 @@ def convert_gedcom_to_markdown(
|
||||
if media_dir and media_dir.exists():
|
||||
logger.info(f"Copying media files to: {media_output_dir}")
|
||||
media_files = []
|
||||
for ext in ['*.jpg', '*.jpeg', '*.png', '*.gif', '*.bmp', '*.JPG', '*.JPEG', '*.PNG']:
|
||||
for ext in [
|
||||
"*.jpg",
|
||||
"*.jpeg",
|
||||
"*.png",
|
||||
"*.gif",
|
||||
"*.bmp",
|
||||
"*.JPG",
|
||||
"*.JPEG",
|
||||
"*.PNG",
|
||||
]:
|
||||
media_files.extend(media_dir.glob(ext))
|
||||
|
||||
copied_count = 0
|
||||
@@ -167,7 +176,7 @@ def convert_gedcom_to_markdown(
|
||||
# Generate index
|
||||
if create_index:
|
||||
logger.info("Generating index file")
|
||||
people_subdir_name = '' if use_flat_structure else 'people'
|
||||
people_subdir_name = "" if use_flat_structure else "people"
|
||||
index_gen = IndexGenerator(output_dir, people_subdir=people_subdir_name)
|
||||
index_path = index_gen.generate_index(individuals)
|
||||
logger.info(f"Created index file: {index_path}")
|
||||
@@ -189,42 +198,40 @@ def convert_gedcom_to_markdown(
|
||||
def main():
|
||||
"""Main entry point for the CLI."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Convert GEDCOM genealogy files to Obsidian markdown notes',
|
||||
epilog='Example: python src/main.py --input family.zip --output vault/family'
|
||||
description="Convert GEDCOM genealogy files to Obsidian markdown notes",
|
||||
epilog="Example: python src/main.py --input family.zip --output vault/family",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-i', '--input',
|
||||
"-i",
|
||||
"--input",
|
||||
type=Path,
|
||||
required=True,
|
||||
metavar='FILE',
|
||||
help='Path to input GEDCOM (.ged) or GEDZIP (.zip) file'
|
||||
metavar="FILE",
|
||||
help="Path to input GEDCOM (.ged) or GEDZIP (.zip) file",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-o', '--output',
|
||||
"-o",
|
||||
"--output",
|
||||
type=Path,
|
||||
required=True,
|
||||
metavar='DIR',
|
||||
help='Output directory for generated notes'
|
||||
metavar="DIR",
|
||||
help="Output directory for generated notes",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--flat',
|
||||
action='store_true',
|
||||
help='Use flat structure (all files in output root). Default creates subdirectories: people/, media/, stories/'
|
||||
"--flat",
|
||||
action="store_true",
|
||||
help="Use flat structure (all files in output root). Default creates subdirectories: people/, media/, stories/",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--no-index',
|
||||
action='store_true',
|
||||
help='Do not create an index file'
|
||||
"--no-index", action="store_true", help="Do not create an index file"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-v', '--verbose',
|
||||
action='store_true',
|
||||
help='Enable verbose logging'
|
||||
"-v", "--verbose", action="store_true", help="Enable verbose logging"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -242,7 +249,7 @@ def main():
|
||||
args.output.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Check if input is a ZIP file
|
||||
is_zip = args.input.suffix.lower() in ['.zip', '.gedzip']
|
||||
is_zip = args.input.suffix.lower() in [".zip", ".gedzip"]
|
||||
temp_dir = None
|
||||
gedcom_file = args.input
|
||||
media_dir = None
|
||||
@@ -250,7 +257,7 @@ def main():
|
||||
try:
|
||||
if is_zip:
|
||||
# Extract ZIP file to temporary directory
|
||||
temp_dir = Path(tempfile.mkdtemp(prefix='gedcom_'))
|
||||
temp_dir = Path(tempfile.mkdtemp(prefix="gedcom_"))
|
||||
gedcom_file, media_dir = extract_gedzip(args.input, temp_dir)
|
||||
|
||||
# Convert
|
||||
@@ -259,7 +266,7 @@ def main():
|
||||
output_dir=args.output,
|
||||
create_index=not args.no_index,
|
||||
media_dir=media_dir,
|
||||
use_flat_structure=args.flat
|
||||
use_flat_structure=args.flat,
|
||||
)
|
||||
|
||||
return exit_code
|
||||
@@ -271,5 +278,5 @@ def main():
|
||||
shutil.rmtree(temp_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user