# 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
"""
Usage: python generate_dossiers_csv.py <api_directory>

Output in <api_directory>:
- dossiers_promulgues.csv with all the doslegs ready
- home.json for the homepage informations
"""


API_DIRECTORY = sys.argv[1]

re_dos_ok = re.compile(r"%s/[^.]+/" % API_DIRECTORY.strip('/'))

# 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

"""
Usage: python generate_dossiers_csv.py <api_directory>

Output in <api_directory>:
- dossiers_promulgues.csv with all the doslegs ready
- home.json for the homepage informations
"""


API_DIRECTORY = sys.argv[1]

re_dos_ok = re.compile(r"%s/[^.]+/" % API_DIRECTORY.strip('/'))

dossiers = [(open_json(path), path) for path \