Skip to content

Commit

Permalink
Fold class attributes into methods if used only once
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jun 2, 2020
1 parent d49fe4b commit 59bcf35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions kingfisher_scrapy/spiders/colombia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class Colombia(LinksSpider):
name = 'colombia'
sleep = 120 * 60
next_page_formatter = parameters('page')

def start_requests(self):
Expand All @@ -27,7 +26,7 @@ def start_requests(self):
def retry(self, response, reason):
url = response.request.url
logging.info(reason.format(url=url, status=response.status))
time.sleep(self.sleep)
time.sleep(120 * 60)
yield scrapy.Request(url, dont_filter=True, meta=response.request.meta)

def parse(self, response):
Expand Down
6 changes: 3 additions & 3 deletions kingfisher_scrapy/spiders/mexico_quien_es_quien.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class MexicoQuienEsQuien(BaseSpider):
name = 'mexico_quien_es_quien'
download_delay = 0.9
url = 'https://api.quienesquien.wiki/v2/contracts?limit={limit}&offset={offset}'

def start_requests(self):
yield scrapy.Request(
Expand All @@ -21,11 +20,12 @@ def start_requests(self):

@handle_error
def parse_list(self, response):
pattern = 'https://api.quienesquien.wiki/v2/contracts?limit={limit}&offset={offset}'
limit = 1000
count = json.loads(response.text)['data'][0]['collections']['contracts']['count']

count = json.loads(response.text)['data'][0]['collections']['contracts']['count']
for offset in range(ceil(count / limit)):
url = self.url.format(limit=limit, offset=offset * limit)
url = pattern.format(limit=limit, offset=offset * limit)
yield self.build_request(url, formatter=parameters('offset'))
if self.sample:
break
Expand Down

0 comments on commit 59bcf35

Please sign in to comment.