import os
import shutil
from fastcore.all import *
base_path = '/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms'
dest_path = '/Users/cck/writings/fractal-llms-nbs/nbs'
def is_lesson(o):
    return "/fractal-llms/0" in str(o)

# files relevant to the lessons
file_formats = [
    ".ipynb", 
    ".jpg", 
    ".png", 
    ".gif", 
    ".jpeg", 
    ".svg", 
    ".txt",
    ".md",
]

def is_lesson_content(o):
    return Path(o).suffix in file_formats
# point to the base notebook repo
bp = Path(base_path)
# find all notebook folders in order
bp = bp.ls().sorted()
lessons = bp.filter(is_lesson); lessons

lessons
(#8) [Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/00-Overview'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/01-env'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/02-nbdev'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/03-hf-nlp-models'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/05-rag'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/06-text-data'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/07-fine-tuning')]
for lesson in lessons:
    # make a new home for the notebooks
    name = lesson.name
    new_lesson = Path(dest_path)/name
    new_lesson.mkdir(exist_ok=True)

    # copy over the content
    for o in lesson.ls().filter(is_lesson_content):
        if o.suffix == ".ipynb":
            fid_name = f'{name}.ipynb'
        else:
            fid_name = o.name
        shutil.copy(o, new_lesson/fid_name)
lessons[-4].ls().filter(is_lesson_content)
(#5) [Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama/llama_description.png'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama/llama-cpp-logo.png'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama/llama_model_support.png'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama/mistral_quantized.png'),Path('/Users/cck/writings/chaski/nbs/blog/posts/fractal-llms/04-llama/index.ipynb')]
o.name
'00-Overview'