Exemplo n.º 1
0
    def setUp(self):
        self.passive = Passive.objects.create(name=u'leonor')
        i = Identifier(
            identifier=
            'http://preproduccion-datos.infolobby.cl:80/resource/URI/Pasivo/0100000035FBA8A3489DC55B38F2412000ECD823B7B037613D60FA221702F4025EF216475E4450578C83800A796A265767CF60B10C5D1C0A3D55C867E588683B758B4B6C684FD3391E2B0601'
        )
        self.passive.identifiers.add(i)

        self.organization = Organization.objects.create(name=u'organization')
        i2 = Identifier(
            identifier=
            'http://preproduccion-datos.infolobby.cl:80/resource/URI/Institucion/AF001'
        )
        self.organization.identifiers.add(i2)
Exemplo n.º 2
0
 def setUp(self):
     self.organization = Organization.objects.create(name=u"The org")
     i = Identifier(
         identifier=
         "http://preproduccion-datos.infolobby.cl:80/resource/URI/Institucion/AF001"
     )
     self.organization.identifiers.add(i)
Exemplo n.º 3
0
 def parse_line(self, line):
     active = Active()
     active.name = unicode(line[3] + " " + line[4])
     active.save()
     seed = line[3] + line[4] + line[5] + line[7]
     i = Identifier(identifier=line[0])
     active.identifiers.add(i)
    def test_use_two_identifiers(self):
        active = Active.objects.create(name=u"Perico los palotes")

        identifier = Identifier(identifier="perico")
        identifier2 = Identifier(identifier="condorito")
        active.identifiers.add(identifier)
        active.identifiers.add(identifier2)

        active_search_one = Active.objects.get(
            identifiers__identifier="perico")
        active_search_two = Active.objects.get(
            identifiers__identifier="condorito")
        self.assertTrue(active_search_one)
        self.assertTrue(active_search_two)
        self.assertEquals(active_search_one.name, u"Perico los palotes")
        self.assertEquals(active_search_two.name, u"Perico los palotes")
    def test_use_identifiers(self):
        active = Active.objects.create(name=u"Perico los palotes")

        identifier = Identifier(identifier="perico")
        active.identifiers.add(identifier)

        active2 = Active.objects.get(identifiers__identifier='perico')
        self.assertTrue(active2)
        self.assertEquals(active2.name, u"Perico los palotes")
 def get_things_from_lines_and_klasses(self, klass, lines, pre_):
     things = []
     problems = []
     for line in lines:
         original_name = name = line[3].decode(
             'utf-8').strip() + u" " + line[4].decode('utf-8').strip()
         ps = self.get_count(klass, name)
         if ps.count() > 1:
             problems.append({'name': name, 'count': ps.count()})
         if not ps:
             name2 = line[3].decode(
                 'utf-8').strip() + u"  " + line[4].decode('utf-8').strip()
             ps = self.get_count(klass, name2)
             if not ps:
                 apellidos = line[4].decode('utf-8').strip().split(" ")
                 if len(apellidos) == 2:
                     apellidos_ = apellidos[0] + " " + apellidos[1]
                     name3 = line[3].decode(
                         'utf-8').strip() + u"  " + apellidos_
                     ps = self.get_count(klass, name3)
                     if not ps:
                         nombres = line[3].decode('utf-8').strip().split(
                             " ")
                         name4 = nombres[0] + u"  " + apellidos_
                         ps = self.get_count(klass, name4)
                         if not ps:
                             instance = klass.objects.create(
                                 name=original_name)
                             i = Identifier(identifier=pre_ + line[0])
                             instance.identifiers.add(i)
                             continue
         if ps.count() == 1:
             i = Identifier(identifier=pre_ + line[0])
             q = ps[0].identifiers.filter(identifier=i.identifier)
             if not q:
                 ps[0].identifiers.add(i)
             else:
                 if q.count() > 1:
                     print q.count()
                     q.exclude(id=q[0].id).delete()
             things.append(ps[0])
     return things, problems
Exemplo n.º 7
0
    def parse(self, response_json, id):
        previous_persons = self.model.objects.filter(
            identifiers__identifier=id)
        if previous_persons:
            return None

        person = self.model()
        for result in response_json['results']['bindings']:
            person = self.extra_processor(result, person)

            if result['property']['value'] == "http://xmlns.com/foaf/0.1/name":
                person.name = result["hasValue"]["value"]
        person.save()
        identifier = Identifier(identifier=id)
        person.identifiers.add(identifier)
        return person
Exemplo n.º 8
0
    def parse(self, response_json, id):
        all_audiencias = Audiencia.objects.filter(identifiers__identifier=id)
        if all_audiencias:
            return
        audiencia = Audiencia()
        active = []
        for result in response_json['results']['bindings']:
            if result['property']['value'].endswith(
                    'resource/cplt/descripcion'):
                audiencia.description = result['hasValue']['value']

            if result['property']['value'].endswith(
                    'resource/cplt/observaciones'):
                audiencia.observations = result['hasValue']['value']

            if result['property']['value'].endswith("resource/cplt/duracion"):
                minutes_scraper = MinutesScraper(requester=self.requester)
                audiencia.length = minutes_scraper.get_one(
                    result['hasValue']['value'])

            if result['property']['value'].endswith(
                    "resource/cplt/registradoPor"):
                organization = Organization.objects.get(
                    identifiers__identifier=result['hasValue']['value'])
                audiencia.registering_organization = organization

            if result['property']['value'].endswith("resource/cplt/inicia"):
                date_scraper = IniciaScraper(requester=self.requester)
                audiencia.date = date_scraper.get_one(
                    result['hasValue']['value'])

            if result['property']['value'].endswith('resource/cplt/participa'):
                person = result['isValueOf']['value']
                try:
                    audiencia.passive = Passive.objects.get(
                        identifiers__identifier=person)
                except Passive.DoesNotExist:
                    active.append(
                        Active.objects.get(identifiers__identifier=person))

        audiencia.save()
        for a in active:
            audiencia.actives.add(a)

        identifier = Identifier(identifier=id)
        audiencia.identifiers.add(identifier)
Exemplo n.º 9
0
    def uri_for_api(self):
        """Return the URL the tastypie API uses to refer to this person"""

        old_url = None
        new_url = None
        for i in self.identifiers.all():
            # If the old identifier exists, use this so that the IDs
            # used in the API don't change.
            if i.scheme == 'popit_url':
                assert old_url is None
                old_url = i.identifier
            # For more recently created Person objects, popolo_uri is
            # the best single identifier to use in the API:
            elif i.scheme == 'popolo_uri':
                assert new_url is None
                new_url = i.identifier
        if old_url:
            return old_url
        if new_url:
            return new_url
        msg = "Could find no global identifier for PopoloPerson with ID {0}"
        raise PopoloIdentifier.DoesNotExist(msg.format(self.pk))
    def parse_entidades(self, *args):
        entidades = {}
        entidades_csv_reader = open(args[1], 'rb')

        lines_for_entidades_loader = csv.reader(entidades_csv_reader,
                                                delimiter=',')
        entidades_lines = []
        for line in lines_for_entidades_loader:
            entidades_lines.append(line)

        for line in entidades_lines:
            entidad = Entidad()
            entidad.rut = line[1].decode('utf-8').strip()
            entidad.name = line[3].decode('utf-8').strip()
            try:
                if line[14] == "True":
                    entidad.remunerado = True
                if line[14] == "False":
                    entidad.remunerado = False
            except:
                pass

            entidad.giro = line[5].decode('utf-8').strip()
            slug = unicodedata.normalize('NFKD', entidad.name).encode(
                'ascii', 'ignore').lower().replace(" ", "")
            id = "entidad_" + line[0]
            if slug in entidades:
                if id not in entidades[slug]['ids']:
                    entidades[slug]['ids'].append(id)
            else:
                entidades[slug] = {'entidad': entidad, 'ids': [id]}

        for slug in entidades:
            e = entidades[slug]
            e['entidad'].save()
            for iden in e['ids']:
                i = Identifier(identifier=iden)
                e['entidad'].identifiers.add(i)
Exemplo n.º 11
0
 def test_instanciate(self):
     organization = Organization.objects.create(name=u"The organization")
     date = timezone.localtime(timezone.now())
     audiencia = Audiencia()
     audiencia.description = "Description"
     audiencia.length = 60
     audiencia.date = date
     audiencia.place = 13101
     audiencia.registering_organization = organization
     audiencia.observations = "Esto puede ser extenso"
     audiencia.passive = self.passive
     audiencia.save()
     identifier = Identifier(identifier='perrito')
     audiencia.identifiers.add(identifier)
     self.assertTrue(audiencia)
     audiencia = Audiencia.objects.get(id=audiencia.id)
     self.assertEquals(audiencia.length, 60)
     self.assertEquals(audiencia.date, date)
     self.assertEquals(audiencia.place, 13101)
     self.assertEquals(audiencia.registering_organization, organization)
     self.assertEquals(audiencia.observations, "Esto puede ser extenso")
     self.assertEquals(audiencia.passive, self.passive)
     self.assertTrue(audiencia.identifiers.all())
     self.assertEquals(audiencia.identifiers.count(), 1)
Exemplo n.º 12
0
 def parse_one_person(self, line, klass, pre_):
     name = line[3].decode('utf-8').strip() + u" " + line[4].decode(
         'utf-8').strip()
     p = klass.objects.get(name=name)
     i = Identifier(identifier=pre_ + line[0].decode('utf-8').strip())
     p.identifiers.add(i)