Пример #1
0
    def next_row(self):
        response = requests.get('https://biodiv-sports.fr/api/v2/sportpractice/')
        if response.status_code != 200:
            msg = _(u"Failed to download https://biodiv-sports.fr/api/v2/sportpractice/. HTTP status code {status_code}")
            raise GlobalImportError(msg.format(url=response.url, status_code=response.status_code))
        for practice in response.json()['results']:
            defaults = {'name_' + lang: practice['name'][lang] for lang in practice['name'].keys() if lang in settings.MODELTRANSLATION_LANGUAGES}
            SportPractice.objects.get_or_create(id=practice['id'], defaults=defaults)
        bbox = Polygon.from_bbox(settings.SPATIAL_EXTENT)
        bbox.srid = settings.SRID
        bbox.transform(4326)  # WGS84
        url = self.url
        url += '&in_bbox={}'.format(','.join([str(coord) for coord in bbox.extent]))
        if self.practices:
            url += '&practices={}'.format(','.join([str(practice) for practice in self.practices]))
        response = requests.get(url)
        if response.status_code != 200:
            msg = _(u"Failed to download {url}. HTTP status code {status_code}")
            raise GlobalImportError(msg.format(url=response.url, status_code=response.status_code))

        self.root = response.json()
        self.nb = int(self.root['count'])

        for row in self.items:
            yield row
Пример #2
0
 def next_row(self):
     while True:
         params = {
             'apiKey': self.api_key,
             'projetId': self.project_id,
             'selectionIds': [self.selection_id],
             'count': self.size,
             'first': self.skip,
             'responseFields': self.responseFields
         }
         response = requests.get(self.url,
                                 params={'query': json.dumps(params)})
         if response.status_code != 200:
             msg = _(
                 u"Failed to download {url}. HTTP status code {status_code}"
             )
             raise GlobalImportError(
                 msg.format(url=response.url,
                            status_code=response.status_code))
         self.root = response.json()
         self.nb = int(self.root['numFound'])
         for row in self.items:
             yield row
         self.skip += self.size
         if self.skip >= self.nb:
             return
Пример #3
0
    def next_row(self):
        response = requests.get(self.url)
        if response.status_code != 200:
            msg = _(u"Failed to download {url}. HTTP status code {status_code}")
            raise GlobalImportError(msg.format(url=response.url,
                                               status_code=response.status_code))

        self.root = response.json()
        self.nb = int(self.root['numFound'])

        for row in self.items:
            yield row
Пример #4
0
 def next_row(self):
     size = 100
     skip = 0
     while True:
         params = {
             'apiKey':
             self.api_key,
             'projetId':
             self.project_id,
             'selectionIds': [self.selection_id],
             'count':
             size,
             'first':
             skip,
             'responseFields': [
                 'id',
                 'nom',
                 'presentation.descriptifCourt',
                 'presentation.descriptifDetaille',
                 'localisation.adresse',
                 'localisation.geolocalisation.geoJson.coordinates',
                 'localisation.geolocalisation.complement.libelleFr',
                 'informations.moyensCommunication',
                 'ouverture.periodeEnClair',
                 'informationsHebergementCollectif.capacite.capaciteTotale',
                 'informationsHebergementCollectif.hebergementCollectifType.libelleFr',
                 'descriptionTarif.tarifsEnClair',
                 'descriptionTarif.modesPaiement',
                 'prestations.services',
                 'gestion.dateModification',
                 'gestion.membreProprietaire.nom',
             ],
         }
         response = requests.get(self.url,
                                 params={'query': json.dumps(params)})
         if response.status_code != 200:
             msg = _(
                 u"Failed to download {url}. HTTP status code {status_code}"
             )
             raise GlobalImportError(
                 msg.format(url=response.url,
                            status_code=response.status_code))
         self.root = response.json()
         self.nb = int(self.root['numFound'])
         for row in self.items:
             yield row
         skip += size
         if skip >= self.nb:
             return
Пример #5
0
 def filter_geom(self, src, val):
     if val is None:
         return None
     if not val.valid:
         self.add_warning(
             _("Invalid geometry for field '{src}'").format(src=src))
         return None
     if val.geom_type == 'MultiPolygon':
         return val
     elif val.geom_type == 'Polygon':
         return MultiPolygon(val)
     raise GlobalImportError(
         _("Invalid geometry type for field '{src}'. "
           "Should be (Multi)Polygon, not {geom_type}").format(
               src=src, geom_type=val.geom_type))
Пример #6
0
    def next_row(self):
        bbox = Polygon.from_bbox(settings.SPATIAL_EXTENT)
        bbox.srid = settings.SRID
        bbox.transform(4326)  # WGS84
        response = requests.get(self.url + "&in_bbox={}".format(",".join(
            [str(coord) for coord in bbox.extent])))
        if response.status_code != 200:
            msg = _(
                u"Failed to download {url}. HTTP status code {status_code}")
            raise GlobalImportError(
                msg.format(url=response.url, status_code=response.status_code))

        self.root = response.json()
        self.nb = int(self.root['count'])

        for row in self.items:
            yield row