From 9e16ae3d9874e48ce1f5f9525d71e7ed2c1a5d89 Mon Sep 17 00:00:00 2001 From: Tom Dickman Date: Sun, 25 Nov 2018 09:40:59 -0500 Subject: [PATCH] Added multipage support to mtc api --- crypto51/apis/mtc.py | 20 ++++++++++++-------- dist/.gitignore | 1 + dist/coins/.gitignore | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 dist/coins/.gitignore diff --git a/crypto51/apis/mtc.py b/crypto51/apis/mtc.py index d56bf6c..912f1b9 100644 --- a/crypto51/apis/mtc.py +++ b/crypto51/apis/mtc.py @@ -6,14 +6,18 @@ class MTC: self._session = HTMLSession() def get_coins(self): - resp = self._session.get('https://minethecoin.com') - for match in resp.html.find('.mineable'): - symbol = match.find('.coin-name', first=True).attrs['title'].split(' - ')[0] - yield { - 'symbol': symbol, - 'name': match.find('.coin-name', first=True).attrs['title'].split(' - ')[1], - 'link': match.find('.coin-name', first=True).attrs['href'] - } + page = 1 + while page: + resp = self._session.get('https://minethecoin.com?page={}'.format(page)) + for match in resp.html.find('.mineable'): + symbol = match.find('.coin-name', first=True).attrs['title'].split(' - ')[0] + yield { + 'symbol': symbol, + 'name': match.find('.coin-name', first=True).attrs['title'].split(' - ')[1], + 'link': match.find('.coin-name', first=True).attrs['href'] + } + # Check if another page exists + page = None if 'disabled' in resp.html.find('.pagination', first=True).find('.page-item')[-1].attrs['class'] else page + 1 def _get_h_hash_rate(self, text): """Convert the hash rate string to a h/s hash rate.""" diff --git a/dist/.gitignore b/dist/.gitignore index d6b7ef3..3c3d032 100644 --- a/dist/.gitignore +++ b/dist/.gitignore @@ -1,2 +1,3 @@ * !.gitignore +!coins/ diff --git a/dist/coins/.gitignore b/dist/coins/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/dist/coins/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore