# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# +
import os
import os.path as op
from datetime import timedelta
from pathlib import Path

import nbformat as nbf
import pandas as pd
import papermill as pm
# -

# Parameters to use later
github_orgs = [
    "jupyterhub",
    "jupyter",
    "jupyterlab",
    "jupyter-widgets",
    "ipython",
    "nteract",
    "executablebooks",
    "voila-dashboards",
]

# # Repository information

# Last 3 months
n_days = 90

# ## Fetch latest data
#
# In this case, we do not save the output notebook because it's just meant for execution.

for org in github_orgs:
    parameters = dict(github_org=org, n_days=n_days)
    pm.execute_notebook(
        "./templates/fetch_data.ipynb",
        os.devnull,
        parameters=parameters,
        nest_asyncio=True,
        cwd="./templates/",
    )

# ## Generate a book from the data

path_book = Path("generated/book")
for org in github_orgs:
    parameters = dict(github_org=org, n_days=n_days)
    path_out = path_book.joinpath(f"{org}.ipynb")
    ntbk = pm.execute_notebook(
        "./templates/org_report.ipynb",
        str(path_out),
        parameters=parameters,
        nest_asyncio=True,
        cwd="./templates/",
    )

    # Remove the param cell so it doesn't show up
    (param_cell,) = [
        cell for cell in ntbk.cells if "injected-parameters" in cell.metadata.tags
    ]
    param_cell.metadata.tags.append("remove-cell")
    nbs = nbf.writes(ntbk)
    nbs = nbs.replace("{{ github_org }}", org)
    path_out.write_text(nbs)

# # People reports

people = [
    "choldgraf",
    "betatim",
    "GeorgianaElena",
    "yuvipanda",
    "consideRatio",
    "chrisjsewell",
    "AakashGfude",
    "mmcky",
]
path_people = Path("generated/people")
for person in people:
    parameters = dict(person=person, n_days=n_days)
    path_out = path_people.joinpath(f"{person}.ipynb")
    ntbk = pm.execute_notebook(
        "./templates/person_report.ipynb",
        str(path_out),
        cwd="./templates/",
        parameters=parameters,
        nest_asyncio=True,
    )

    # Remove the param cell so it doesn't show up
    (param_cell,) = [
        cell for cell in ntbk.cells if "injected-parameters" in cell.metadata.tags
    ]
    param_cell.metadata.tags.append("remove-cell")
    nbs = nbf.writes(ntbk)
    nbs = nbs.replace("{{ person }}", person)
    path_out.write_text(nbs)

StarcoderdataJupyterScriptsDedupFiltered