# Path: tlfp/tools/common.py
# def open_json(dirpath, filename=None):
#     if filename:
#         path = os.path.join(dirpath, filename)
#     else:
#         path = dirpath
#     try:
#         with open(path, 'r') as f:
#             return json.load(f)
#     except Exception as e:
#         print(type(e), e, file=sys.stderr)
#         sys.stderr.write("ERROR: Could not open file %s" % (path,))
#         raise e


import glob
import os
import sys
import shutil
import shlex
import gitlab
from pathlib import Path
from tlfp.tools.common import open_json
            gituser = "conseil_constitutionnel"
        elif instit == "congrès":
            author = "Congrès"
            author_email = "contact@assemblee-nationale.fr"  # ?
            gituser = "congrès"
        else:
            raise Exception("Unknown author: %s" % instit)

        # ID=$(echo $line | awk -F ';' '{print $7}')

        # DATE=$(echo $line | awk -F ';' '{print $14}')
        #  DATE=$(date --date="$DATE" -R);
        date = step.get("date")

        if "directory" not in step or step.get("debats_order") is None:
            continue

        texte_path = os.path.join(
            project_dir, "procedure", step.get("directory"), "texte/texte.json"
        )
        texte = read_text(texte_path)
        if texte:
            text_dest = git_dir / "texte"
            with open(str(text_dest), "w") as f:
                f.write(texte)

            #  echo $line | awk -F ';' '{print $2}' > texte/titre.txt

            r"""
            find texte -name *json -exec rm '{}' ';'

# Path: tlfp/tools/common.py
# def open_json(dirpath, filename=None):
#     if filename:
#         path = os.path.join(dirpath, filename)
#     else:
#         path = dirpath
#     try:
#         with open(path, 'r') as f:
#             return json.load(f)
#     except Exception as e:
#         print(type(e), e, file=sys.stderr)
#         sys.stderr.write("ERROR: Could not open file %s" % (path,))
#         raise e


# Path: tlfp/tools/make_git_repos.py
import glob
import os
import sys
import shutil
import shlex
import gitlab
from pathlib import Path
from tlfp.tools.common import open_json

            gituser = "conseil_constitutionnel"
        elif instit == "congrès":
            author = "Congrès"
            author_email = "contact@assemblee-nationale.fr"  # ?
            gituser = "congrès"
        else:
            raise Exception("Unknown author: %s" % instit)

        # ID=$(echo $line | awk -F ';' '{print $7}')

        # DATE=$(echo $line | awk -F ';' '{print $14}')
        #  DATE=$(date --date="$DATE" -R);
        date = step.get("date")

        if "directory" not in step or step.get("debats_order") is None:
            continue

        texte_path = os.path.join(
            project_dir, "procedure", step.get("directory"), "texte/texte.json"
        )
        texte = read_text(texte_path)
        if texte:
            text_dest = git_dir / "texte"
            with open(str(text_dest), "w") as f:
                f.write(texte)

            #  echo $line | awk -F ';' '{print $2}' > texte/titre.txt

            r"""
            find texte -name *json -exec rm '{}' ';'

            find texte -name '*alineas' | sed 's/\(.*\)/mv "\1" "\1"/' | sed 's|[^/]*$|article.txt"|' | sh