Skip to content

Commit

Permalink
Merge 0c9c893 into 273a7b4
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilerapy committed Jun 19, 2020
2 parents 273a7b4 + 0c9c893 commit 169e7c8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions kingfisher_scrapy/spiders/moldova_mtender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json

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


class MoldovaMTender(SimpleSpider):
"""
Spider arguments
sample
Download only one set of releases.
"""
name = 'moldova_mtender'
data_type = 'release_package'
base_url = 'http://public.eprocurement.systems/ocds/tenders/'

def start_requests(self):
url = 'https://public.mtender.gov.md/tenders/'
yield self.build_request(url, formatter=components(-1), callback=self.parse_list)

@handle_http_error
def parse_list(self, response):
data = json.loads(response.text)
# The last page returns an empty JSON object.
if not data:
return
for item in data['data']:
yield self.build_request(self.base_url + item['ocid'], formatter=components(-2))

if self.sample:
return

url = replace_parameter(response.request.url, 'offset', data['offset'])
yield self.build_request(url, formatter=join(components(-1), parameters('offset')), callback=self.parse_list)

0 comments on commit 169e7c8

Please sign in to comment.