Skip to content

Commit

Permalink
Merge pull request #617 from open-contracting/fix-france
Browse files Browse the repository at this point in the history
france: change url to a direct to OCDS one
  • Loading branch information
yolile committed Feb 23, 2021
2 parents 60bb9aa + 7969568 commit b0d38da
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions kingfisher_scrapy/spiders/france.py
@@ -1,7 +1,7 @@
import scrapy

from kingfisher_scrapy.base_spider import SimpleSpider
from kingfisher_scrapy.util import components, handle_http_error, parameters
from kingfisher_scrapy.util import components, handle_http_error


class France(SimpleSpider):
Expand All @@ -19,18 +19,14 @@ class France(SimpleSpider):
def start_requests(self):
# A CKAN API JSON response.
# Ministère de l'économie, des finances et de la relance
url = 'https://www.data.gouv.fr/api/1/datasets/?organization=534fff8ea3a7292c64a77f02'
url = 'https://www.data.gouv.fr/api/1/datasets/donnees-essentielles-de-la-commande-publique-fichiers' \
'-consolides/'
yield scrapy.Request(url, meta={'file_name': 'page-1.json'}, callback=self.parse_list)

@handle_http_error
def parse_list(self, response):
data = response.json()
for item in data['data']:
for resource in item['resources']:
description = resource['description']
if description and 'ocds' in description.lower():
yield self.build_request(resource['url'], formatter=components(-2))

next_page = data.get('next_page')
if next_page:
yield self.build_request(next_page, formatter=parameters('page'), callback=self.parse_list)
for resource in data['resources']:
description = resource['description']
if description and 'ocds' in description.lower():
yield self.build_request(resource['url'], formatter=components(-2))

0 comments on commit b0d38da

Please sign in to comment.