Esempio n. 1
0
def add_addrs(mep, addrs):
    if addrs.get("Brussels"):
        print "     add Brussels infos"
        bxl = addrs["Brussels"]
        if bxl["Address"].get("building_code"):
            mep.bxl_building = get_or_create(Building, _id="id",
                                         id=bxl["Address"]["building_code"],
                                         name=bxl["Address"]["Building"],
                                         street=bxl["Address"]["Street"],
                                         postcode=bxl["Address"]["Zip"])
        mep.bxl_floor = bxl["Address"]["Office"][:2]
        mep.bxl_office_number = bxl["Address"]["Office"][2:]
        mep.bxl_fax = bxl["Fax"]
        mep.bxl_phone1 = bxl["Phone"]
        mep.bxl_phone2 = bxl["Phone"][:-4] + "7" + bxl["Phone"][-3:]
    print "     add Strasbourg infos"
    if addrs.get("Strasbourg"):
        stg = addrs["Strasbourg"]
        if stg["Address"].get("building_code"):
            mep.stg_building = get_or_create(Building, _id="id",
                                         id=stg["Address"]["building_code"],
                                         name=stg["Address"]["Building"],
                                         street=stg["Address"]["Street"],
                                         postcode=stg["Address"].get("Zip", stg["Address"]["Zip1"]))
        mep.stg_floor = stg["Address"]["Office"][:3]
        mep.stg_office_number = stg["Address"]["Office"][3:]
        mep.stg_fax = stg["Fax"]
        mep.stg_phone1 = stg["Phone"]
        mep.stg_phone2 = stg["Phone"][:-4] + "7" + stg["Phone"][-3:]
        print "     adding mep's postal addresses:"
    mep.save()
    PostalAddress.objects.filter(mep=mep).delete()
    for addr in addrs.get("Postal", []):
        print "       *", addr.encode("Utf-8")
        PostalAddress.objects.create(addr=addr, mep=mep)
Esempio n. 2
0
def add_assistants(mep, assistants):
    print "Assistants for " + mep.full_name.encode("Utf-8")
    for assist_type in assistants:
        print "TYPE : " + assist_type.encode("Utf-8")
        type_name = assist_type
        for assistant in assistants[type_name]:
            print assistant.encode("Utf-8")
            assistant = get_or_create(Assistant, full_name=assistant)
            get_or_create(AssistantMEP, mep=mep, assistant=assistant, type=type_name)
Esempio n. 3
0
def handle_function(i, _mp, extra):
    function = i["responsabilite"]
    if function["organisme"].startswith("Bureau"):
        tipe = "bureau"
    elif function["organisme"].encode("Utf-8").startswith("Comité") or function["organisme"].encode("Utf-8").startswith(
        "Comuté"
    ):
        tipe = u"comité"
    elif (
        function["organisme"].startswith("Commission")
        or function["organisme"].startswith("Commision")
        or function["organisme"].startswith("Ccommission")
    ):
        tipe = "commission"
    elif function["organisme"].encode("Utf-8").startswith("Délégation"):
        tipe = "déléguation"
    elif function["organisme"].encode("Utf-8").startswith("Observatoire"):
        tipe = "observatoire"
    elif function["organisme"].startswith("Mission") or "- mission" in function["organisme"]:
        tipe = "mission"
    elif function["organisme"].encode("Utf-8").startswith("Office parlementaire"):
        tipe = "office"
    elif function["organisme"].encode("Utf-8").startswith("Groupe de travail"):
        tipe = "groupe de travail"
    elif function["organisme"].encode("Utf-8").startswith("Conseil") or "conseil" in function["organisme"]:
        tipe = "conseil"
    elif function["organisme"].encode("Utf-8").startswith("Groupe français"):
        tipe = "autre"
    elif (
        function["organisme"]
        .encode("Utf-8")
        .startswith("écologie, du développement durable, des transports et du logement")
    ):
        tipe = "autre"
    elif (
        function["organisme"]
        .encode("Utf-8")
        .startswith("Modalités de création des brigades de police spécialisées dans la prise en charge des mineurs dél")
    ):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Section française de "):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Cour de justice de la république"):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Conférence"):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Agence nationale"):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Haut comité"):
        tipe = "autre"
    elif function["organisme"].encode("Utf-8").startswith("Institut"):
        tipe = "autre"
    else:
        print function["organisme"]
        raise Exception
    new_function = get_or_create(Function, title=function["organisme"], type=tipe)
    get_or_create(FunctionMP, mp=_mp, function=new_function, role=function["fonction"], extra_parliamentary=extra)
Esempio n. 4
0
def get_etudes_groups(_mp, mp):
    for i in mp["groupes_parlementaires"]:
        group = i["responsabilite"]
        tipe = " ".join(group["organisme"].split()[:2])
        title = " ".join(group["organisme"].split()[2:])
        if tipe.encode("Utf-8") not in ("Groupe d'amitié", "Groupe d'études"):
            print group["organisme"]
            raise Exception

        function = get_or_create(Function, title=title, type=tipe)
        get_or_create(FunctionMP, mp=_mp, function=function, role=group["fonction"], extra_parliamentary=False)
Esempio n. 5
0
def add_delegations(mep, delegations):
    DelegationRole.objects.filter(mep=mep).delete()
    for delegation in delegations:
        db_delegation = get_or_create(Delegation, name=delegation["Organization"])
        print "     create DelegationRole to link mep to delegation"
        params={}
        if delegation.get("start"):
            params['begin']=_parse_date(delegation["start"])
        if delegation.get("end"):
            params['end']=_parse_date(delegation["end"])
        DelegationRole.objects.create(mep=mep, delegation=db_delegation,
                                      role=delegation["role"], **params)
Esempio n. 6
0
def add_organizations(mep, organizations):
    OrganizationMEP.objects.filter(mep=mep).delete()
    for organization in organizations:
        in_db_organization = get_or_create(Organization, name=organization["Organization"])
        print "     link mep to organization:", in_db_organization.name
        params={}
        if organization.get("start"):
            params['begin']=_parse_date(organization["start"])
        if organization.get("end"):
            params['end']=_parse_date(organization["end"])
        OrganizationMEP.objects.create(mep=mep,
                                       organization=in_db_organization,
                                       role=organization["role"], **params)
Esempio n. 7
0
def add_countries(mep, countries):
    PartyRepresentative.objects.filter(representative=mep.representative_ptr).delete()
    CountryMEP.objects.filter(mep=mep).delete()
    print "     add countries"
    for country in countries:
        print country
        print "     link mep to country", '"%s"' % country["country"], "for a madate"
        _country = Country.objects.get(name=country["country"])
        print "     link representative to party"
        if "party" in country:
            party = get_or_create(LocalParty, name=country["party"], country=_country)
            if not PartyRepresentative.objects.filter(representative=mep.representative_ptr, party=party):
                #current = True if _parse_date(country["end"]).year > date.today().year else False
                current = 'end' not in country
                PartyRepresentative.objects.create(representative=mep.representative_ptr,
                                                   party=party, current=current)
        else: party=get_or_create(LocalParty, name="unknown", country=_country)
        params={}
        if country.get("start"):
            params['begin']=_parse_date(country["start"])
        if country.get("end"):
            params['end']=_parse_date(country["end"])
        CountryMEP.objects.create(mep=mep, country=_country, party=party, **params)
Esempio n. 8
0
def update_group_info(_mp, mp):
    an_id = mp["url_an"].split("/")[-1].split(".")[0]
    if an_id in (
        "1931",
        "267553",
        "267456",
        "2090",
        "2769",
        "632",
        "2681",
        "331339",
        "333224",
        "267419",
        "267605",
        "408269",
        "1236",
        "1310",
        "332",
        "267165",
        "346886",
        "1068",
        "267285",
        "345727",
        "331481",
        "267872",
        "267591",
        "2107",
        "430",
    ):  # mp for which I have data but RC don't
        return
    if an_id in ("267765",):
        _mp.group = get_or_create(Group, abbreviation="NI", name=u"Députés n'appartenant à aucun groupe")
        return
    _mp.group_role = mp["groupe"]["fonction"]
    _mp.group = get_or_create(
        Group, _id="abbreviation", abbreviation=mp["groupe_sigle"], name=mp["groupe"]["organisme"]
    )
Esempio n. 9
0
def get_department_and_circo(mp, _mp):
    if mp["num_deptmt"] in (999, "999"):
        department = get_or_create(Department, name="Etranger", number="999")
    elif mp["num_deptmt"] != 0:
        try:
            department = Department.objects.get(number=mp["num_deptmt"])
        except:
            if mp["num_deptmt"] == "977":
                department = Department.objects.create(number="977", name=mp["nom_circo"])
            else:
                print "[Error] Department not in database : " + mp["num_deptmt"]
                return
    else:  # TOREMOVE: code is fixed on nosdeputes side but cache is still active
        department = Department.objects.get(number=987)
    if mp["num_circo"] != 1:
        number = str(mp["num_circo"]) + "ème"
    else:
        number = str(mp["num_circo"]) + "ère"
    _mp.department = department
    try:
        _mp.circonscription = Circonscription.objects.get(number=number, department=department)
    except:
        _mp.circonscription = get_or_create(Circonscription, number=number, department=department)
        print "[Warning] Created new Circonscription : " + number
Esempio n. 10
0
def add_mep_cv(mep, cv):
    for c in cv:
        if c:
            get_or_create(CV, title=c, representative=mep.representative_ptr)
Esempio n. 11
0
def add_mep_website(mep, urls):
    for url in urls:
        get_or_create(WebSite, representative=mep.representative_ptr, url=url)
Esempio n. 12
0
def add_mep_email(mep, emails):
    if isinstance(emails, list):
        for email in emails:
            get_or_create(Email, representative=mep.representative_ptr, email=email)
    else:
        get_or_create(Email, representative=mep.representative_ptr, email=emails)
Esempio n. 13
0
def get_mandate(mp, _mp):
    for mandate in mp["mandat_debut"]:
        get_or_create(Mandate, begin_term=mandate["mandat_debut"], representative=_mp.representative_ptr)
Esempio n. 14
0
def get_new_emails(mp, _mp):
    for email in mp["emails"]:
        get_or_create(Email, email=email["email"], representative=_mp.representative_ptr)
Esempio n. 15
0
def get_new_websites(mp, _mp):
    if mp["sites_web"]:
        for website in mp["sites_web"]:
            get_or_create(WebSite, url=website["site"], representative=_mp.representative_ptr)