def parse_national_assembly_url(url_an):
    """Returns the slug and the legislature of an AN url

    >>> # old format
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/devoir_vigilance_entreprises_donneuses_ordre.asp")
    (14, 'devoir_vigilance_entreprises_donneuses_ordre')
    >>> # new format
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/dyn/15/dossiers/retablissement_confiance_action_publique")
    (15, 'retablissement_confiance_action_publique')
    >>> # sometimes there's a linked subsection, it's the real dosleg ID, we only use it if we are in the 15th legislature
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/le_dossier.asp#deuxieme_partie")
    (14, 'le_dossier')
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/15/dossiers/le_nouveau_dossier.asp#deuxieme_partie")
    (15, 'deuxieme_partie')
    >>> # some dossier-like urls are not actual dossiers
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/motion_referendaire_2097.pdf")
    (14, None)

    """
    legislature_match = re.search(r"\.fr/(dyn/)?(\d+)/", url_an)
    if legislature_match:
        legislature = int(legislature_match.group(2))
    else:
        legislature = None

    slug = None
    slug_match = re.search(r"/([\w_\-]*)(?:\.asp)?(?:#([\w_\-]*))?$", url_an)
    if slug_match:
        if legislature and legislature > 14:
            slug = slug_match.group(2) or slug_match.group(1)
        else:
            slug = slug_match.group(1)

    return legislature, slug
def parse_national_assembly_url ( url_an ) : legislature_match = re . search ( r"\.fr/(dyn/)?(\d+)/" , url_an ) if legislature_match : legislature = int ( legislature_match . group ( 2 ) ) else : legislature = None slug = None slug_match = re . search ( r"/([\w_\-]*)(?:\.asp)?(?:#([\w_\-]*))?$" , url_an ) if slug_match : if legislature and legislature > 14 : slug = slug_match . group ( 2 ) or slug_match . group ( 1 ) else : slug = slug_match . group ( 1 ) return legislature , slug
Returns the slug and the legislature of an AN url

    >>> # old format
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/devoir_vigilance_entreprises_donneuses_ordre.asp")
    (14, 'devoir_vigilance_entreprises_donneuses_ordre')
    >>> # new format
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/dyn/15/dossiers/retablissement_confiance_action_publique")
    (15, 'retablissement_confiance_action_publique')
    >>> # sometimes there's a linked subsection, it's the real dosleg ID, we only use it if we are in the 15th legislature
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/le_dossier.asp#deuxieme_partie")
    (14, 'le_dossier')
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/15/dossiers/le_nouveau_dossier.asp#deuxieme_partie")
    (15, 'deuxieme_partie')
    >>> # some dossier-like urls are not actual dossiers
    >>> parse_national_assembly_url("http://www.assemblee-nationale.fr/14/dossiers/motion_referendaire_2097.pdf")
    (14, None)