Skip to content

Commit

Permalink
Merge 4124492 into 8eaeda4
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilerapy committed Nov 4, 2020
2 parents 8eaeda4 + 4124492 commit 2514901
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/spiders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,16 @@ Spain
scrapy crawl spain_zaragoza
Tanzania
--------

.. autoclass:: kingfisher_scrapy.spiders.tanzania_zabuni.TanzaniaZabuni
:no-members:

.. code-block:: bash
scrapy crawl tanzania_zabuni
Uganda
------

Expand Down
37 changes: 37 additions & 0 deletions kingfisher_scrapy/spiders/tanzania_zabuni.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

import scrapy

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


class TanzaniaZabuni(SimpleSpider):
"""
Domain
Tanzania Zabuni
API documentation
https://zabuni.co.tz/docs
"""
name = 'tanzania_zabuni'
data_type = 'release_package'
url = 'https://app.zabuni.co.tz/api/releases/{}'
download_delay = 1 # to avoid API 429 error "too many request"

def start_requests(self):
stages = ['tender', 'award', 'contract']
for stage in stages:
yield scrapy.Request(
self.url.format(stage),
meta={'file_name': 'list.json', 'stage': stage},
callback=self.parse_list
)

@handle_http_error
def parse_list(self, response):
releases = json.loads(response.text)['releases']
for release in releases:
yield self.build_request(
self.url.format(f"{release['ocid']}/{response.request.meta['stage']}"),
formatter=components(-2)
)

0 comments on commit 2514901

Please sign in to comment.