# Path: tlfp/tools/common.py
# def download_daily(url_or_collecter, filename, output_directory):
#     if not os.path.exists(output_directory):
#         os.makedirs(output_directory)
#     yesterday = time.time() - 86400
#     destfile = os.path.join(output_directory, filename + ".json")
#     if not os.path.exists(destfile) or os.path.getmtime(destfile) < yesterday:
#         print('downloading', filename)
#         if isinstance(url_or_collecter, str):
#             jsondata = download(url_or_collecter).json()
#         else:
#             jsondata = url_or_collecter()
#         print_json(jsondata, destfile)
#     else:
#         jsondata = open_json(destfile)
#     return jsondata


import sys
from lawfactory_utils.urls import download, enable_requests_cache
from .common import download_daily




def process(output_directory):
    for url in "2007-2012.nosdeputes", "2012-2017.nosdeputes", "2017-2022.nosdeputes", "www.nosdeputes", "www.nossenateurs":
        download_daily(
            "https://%s.fr/organismes/groupe/json" % url,
            '%s-groupes' % url,
            output_directory
        )

# Path: tlfp/tools/common.py
# def download_daily(url_or_collecter, filename, output_directory):
#     if not os.path.exists(output_directory):
#         os.makedirs(output_directory)
#     yesterday = time.time() - 86400
#     destfile = os.path.join(output_directory, filename + ".json")
#     if not os.path.exists(destfile) or os.path.getmtime(destfile) < yesterday:
#         print('downloading', filename)
#         if isinstance(url_or_collecter, str):
#             jsondata = download(url_or_collecter).json()
#         else:
#             jsondata = url_or_collecter()
#         print_json(jsondata, destfile)
#     else:
#         jsondata = open_json(destfile)
#     return jsondata


# Path: tlfp/tools/download_groupes.py
import sys
from lawfactory_utils.urls import download, enable_requests_cache
from .common import download_daily





def process(output_directory):
    for url in "2007-2012.nosdeputes", "2012-2017.nosdeputes", "2017-2022.nosdeputes", "www.nosdeputes", "www.nossenateurs":
        download_daily(
            "https://%s.fr/organismes/groupe/json" % url,
            '%s-groupes' % url,
            output_directory
        )

        download_daily(