# Path: tlfp/tools/common.py
# def log_print(file=None, only_log=False):
#         def __init__(self, file):
#         def write(self, message):
#         def __getattr__(self, attr):
# def open_csv(dirpath, filename, delimiter=";"):
# def open_json(dirpath, filename=None):
# def download_daily(url_or_collecter, filename, output_directory):
# def print_json(dico, filename=None):
# def debug_file(data, filename):
# def format_date(d):
# def format_display_date(d):
# def real_lower(text):
# def clean_accents(text):
# def clean_text_for_diff(text):
# def compute_approx_similarity(text1, text2):
# def compute_similarity(text1, text2):
# def compute_similarity_by_articles(text1, text2):
# def identify_room(url_or_institution, legislature):
# def national_assembly_text_legislature(url_text):
# def personalize_link(link, obj, urlapi):
# def slug_groupe(g):
#     def __init__(self, sourcedir, load_parls=False):
#     def get_procedure(self):
#     def get_parlementaires(self):
#     def get_parlementaire(self, urlapi, slug):
#     def get_groupes(self):
#     def get_historique_groupes_senat(self):
#     def get_senateur_groupe(self, slug, object_date, urlapi):
#     def add_groupe(self, groupes, gpe, urlapi):
# def get_text_id(texte_url):
#     class Logger:
# class Context(object):
# 
# Path: tlfp/tools/generate_sitemap.py
# def generate_sitemap(doslegs, api_directory):
#     urls = [
#             L.url / [
#                 L.loc / f"https://www.lafabriquedelaloi.fr/articles.html?loi={dos['id']}",
#                 L.lastmod / datetime.datetime.now().strftime('%Y-%m-%d'), # TODO: use directory last modified date
#                 L.changefreq / ("monthly" if dos.get('url_jo') else "daily"),
#                 L.priority / "1.0",
#             ]
#           for dos, _ in doslegs
#     ]
# 
#     other_urls = [
#         ("https://www.lafabriquedelaloi.fr/", "daily"),
#         ("https://www.lafabriquedelaloi.fr/a-propos.html", "monthly"),
#         ("https://www.lafabriquedelaloi.fr/lois.html", "daily"),
#         ("https://www.lafabriquedelaloi.fr/lois.html?encours", "daily"),
#     ]
# 
#     urls += [
#             L.url / [
#                 L.loc / url,
#                 L.lastmod / datetime.datetime.now().strftime('%Y-%m-%d'),
#                 L.changefreq / changefreq,
#                 L.priority / "1.0",
#             ]
#           for url, changefreq in other_urls
#     ]
# 
#     result = render([
#         raw("""<?xml version="1.0" encoding="UTF-8"?>"""),
#         L.urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") / urls
#     ])
#     open(os.path.join(api_directory, 'sitemap.xml'), 'w').write(result)


import glob, os, sys, csv, re, copy, datetime
from tlfp.tools.common import upper_first, open_json, print_json
from tlfp.tools.generate_sitemap import generate_sitemap
    decision_cc_date = None
    for step in dos['steps']:
        if step.get('stage') == 'constitutionnalité':
            decision_cc = step.get('decision')
            decision_cc_date = step.get('date')
            break

    csvfile.writerow([
        dos['id'], # id
        dos.get('long_title'), # Titre
        'proposition de loi' if dos.get('proposal_type') == 'PPL' else 'projet de loi', # Type de dossier
        dos.get('beginning'), # Date initiale
        dos.get('url_dossier_senat', dos.get('url_dossier_assemblee')), # URL du dossier
        'promulgué' if dos.get('end') else '', # État du dossier
        decision_cc, # Décision du CC
        decision_cc_date, # Date de la décision
        dos.get('end'), # Date de promulgation
        dos.get('law_name'), # Numéro de la loi
        ','.join(dos.get('themes', [])), # Thèmes
        dos['stats']['total_amendements'], # total_amendements
        dos['stats']['total_mots'], # total_mots
        dos.get('short_title'), # short_title
        dos.get('loi_dite'), # Nom commun de la loi
        dos.get('assemblee_id'), # ex: 14-peche_et_chasse
    ])

    # format data for home.json
    if dos['stats']['total_amendements']:
        title = dos.get('short_title')
        if dos.get('loi_dite'):

# Path: tlfp/tools/common.py
# def log_print(file=None, only_log=False):
#         def __init__(self, file):
#         def write(self, message):
#         def __getattr__(self, attr):
# def open_csv(dirpath, filename, delimiter=";"):
# def open_json(dirpath, filename=None):
# def download_daily(url_or_collecter, filename, output_directory):
# def print_json(dico, filename=None):
# def debug_file(data, filename):
# def format_date(d):
# def format_display_date(d):
# def real_lower(text):
# def clean_accents(text):
# def clean_text_for_diff(text):
# def compute_approx_similarity(text1, text2):
# def compute_similarity(text1, text2):
# def compute_similarity_by_articles(text1, text2):
# def identify_room(url_or_institution, legislature):
# def national_assembly_text_legislature(url_text):
# def personalize_link(link, obj, urlapi):
# def slug_groupe(g):
#     def __init__(self, sourcedir, load_parls=False):
#     def get_procedure(self):
#     def get_parlementaires(self):
#     def get_parlementaire(self, urlapi, slug):
#     def get_groupes(self):
#     def get_historique_groupes_senat(self):
#     def get_senateur_groupe(self, slug, object_date, urlapi):
#     def add_groupe(self, groupes, gpe, urlapi):
# def get_text_id(texte_url):
#     class Logger:
# class Context(object):
# 
# Path: tlfp/tools/generate_sitemap.py
# def generate_sitemap(doslegs, api_directory):
#     urls = [
#             L.url / [
#                 L.loc / f"https://www.lafabriquedelaloi.fr/articles.html?loi={dos['id']}",
#                 L.lastmod / datetime.datetime.now().strftime('%Y-%m-%d'), # TODO: use directory last modified date
#                 L.changefreq / ("monthly" if dos.get('url_jo') else "daily"),
#                 L.priority / "1.0",
#             ]
#           for dos, _ in doslegs
#     ]
# 
#     other_urls = [
#         ("https://www.lafabriquedelaloi.fr/", "daily"),
#         ("https://www.lafabriquedelaloi.fr/a-propos.html", "monthly"),
#         ("https://www.lafabriquedelaloi.fr/lois.html", "daily"),
#         ("https://www.lafabriquedelaloi.fr/lois.html?encours", "daily"),
#     ]
# 
#     urls += [
#             L.url / [
#                 L.loc / url,
#                 L.lastmod / datetime.datetime.now().strftime('%Y-%m-%d'),
#                 L.changefreq / changefreq,
#                 L.priority / "1.0",
#             ]
#           for url, changefreq in other_urls
#     ]
# 
#     result = render([
#         raw("""<?xml version="1.0" encoding="UTF-8"?>"""),
#         L.urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") / urls
#     ])
#     open(os.path.join(api_directory, 'sitemap.xml'), 'w').write(result)


# Path: tlfp/generate_dossiers_csv.py
import glob, os, sys, csv, re, copy, datetime
from tlfp.tools.common import upper_first, open_json, print_json
from tlfp.tools.generate_sitemap import generate_sitemap

    decision_cc_date = None
    for step in dos['steps']:
        if step.get('stage') == 'constitutionnalité':
            decision_cc = step.get('decision')
            decision_cc_date = step.get('date')
            break

    csvfile.writerow([
        dos['id'], # id
        dos.get('long_title'), # Titre
        'proposition de loi' if dos.get('proposal_type') == 'PPL' else 'projet de loi', # Type de dossier
        dos.get('beginning'), # Date initiale
        dos.get('url_dossier_senat', dos.get('url_dossier_assemblee')), # URL du dossier
        'promulgué' if dos.get('end') else '', # État du dossier
        decision_cc, # Décision du CC
        decision_cc_date, # Date de la décision
        dos.get('end'), # Date de promulgation
        dos.get('law_name'), # Numéro de la loi
        ','.join(dos.get('themes', [])), # Thèmes
        dos['stats']['total_amendements'], # total_amendements
        dos['stats']['total_mots'], # total_mots
        dos.get('short_title'), # short_title
        dos.get('loi_dite'), # Nom commun de la loi
        dos.get('assemblee_id'), # ex: 14-peche_et_chasse
    ])

    # format data for home.json
    if dos['stats']['total_amendements']:
        title = dos.get('short_title')
        if dos.get('loi_dite'):

            title = "%s (%s)" % (upper_first(dos.get('loi_dite')), title)