# 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
            if art["alineas"][key] != "":
                texte += art["alineas"][key] + "\n\n"
    return texte


def call(cmd):
    code = os.system(cmd)
    if code != 0:
        raise Exception('"{}"" returned {}'.format(cmd, code))


def call_bash(cmd):
    call("bash -c " + shlex.quote(cmd))


GIT_REPOS_DIRECTORY = sys.argv[1]


GITLAB_TOKEN = sys.argv[2] if len(sys.argv) == 3 else None
if GITLAB_TOKEN:
    gl = gitlab.Gitlab('https://git.regardscitoyens.org/', private_token=GITLAB_TOKEN)
    group = gl.groups.list(search='parlement')[0]

    # delete existing bills
    projects = group.projects.list()
    for project in projects:
        print('delete', project.id)
        gl.projects.delete(project.id)

for procedure_file in sorted(glob.glob("data/**/procedure.json", recursive=True)):

# 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

            if art["alineas"][key] != "":
                texte += art["alineas"][key] + "\n\n"
    return texte


def call(cmd):
    code = os.system(cmd)
    if code != 0:
        raise Exception('"{}"" returned {}'.format(cmd, code))


def call_bash(cmd):
    call("bash -c " + shlex.quote(cmd))


GIT_REPOS_DIRECTORY = sys.argv[1]


GITLAB_TOKEN = sys.argv[2] if len(sys.argv) == 3 else None
if GITLAB_TOKEN:
    gl = gitlab.Gitlab('https://git.regardscitoyens.org/', private_token=GITLAB_TOKEN)
    group = gl.groups.list(search='parlement')[0]

    # delete existing bills
    projects = group.projects.list()
    for project in projects:
        print('delete', project.id)
        gl.projects.delete(project.id)

for procedure_file in sorted(glob.glob("data/**/procedure.json", recursive=True)):

    procedure = open_json(procedure_file)