Skip to content

Commit 4c19676

Browse files
ddxvdale-wahl
andauthored
Unlimit search result (#12)
* Allow setting limit to none to return all search results returned by apple api * Allow setting limit to none to return all search results returned by apple api * update .gitignore * add multipage test --------- Co-authored-by: Dale Wahl <[email protected]>
1 parent 48d4efd commit 4c19676

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ itunes_app_scraper/__pycache__
33
__pycache__
44
.pytest_cache
55
log/*
6-
.idea/
6+
.idea/
7+
8+
build/
9+
dist/
10+
*.egg-info/

features/scraper.feature

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ Feature: scraper initial
1010
When we search for result from mindful
1111
Then the scraper will return "15" results
1212

13-
Scenario: run a collections search
14-
Given we have itunes scraper installed
15-
When we search for the topic topfreeapplications
16-
Then the scraper will return "50" results
17-
1813
Scenario: run a developer search
1914
Given we have itunes scraper installed
2015
When we search for the developer 384434796
@@ -39,4 +34,4 @@ Feature: scraper initial
3934
Scenario: read app details for pokemon
4035
Given we have itunes scraper installed
4136
When we search for the app with id "1094591345"
42-
Then the title is "Pokémon GO"
37+
Then the title is "Pokémon GO"

itunes_app_scraper/scraper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def get_app_ids_for_query(self, term, num=50, page=1, country="nl", lang="nl"):
3030
Retrieve suggested app IDs for search query
3131
3232
:param str term: Search query
33-
:param int num: Amount of items to return per page, default 50
34-
:param int page: Amount of pages to return
33+
:param int|None num: Amount of items to return per page, default 50
34+
:param int|None page: Amount of pages to return
3535
:param str country: Two-letter country code of store to search in,
3636
default 'nl'
3737
:param str lang: Language code to search with, default 'nl'
@@ -44,7 +44,10 @@ def get_app_ids_for_query(self, term, num=50, page=1, country="nl", lang="nl"):
4444
url = "https://search.itunes.apple.com/WebObjects/MZStore.woa/wa/search?clientApplication=Software&media=software&term="
4545
url += quote_plus(term)
4646

47-
amount = int(num) * int(page)
47+
if num is None or page is None:
48+
amount = None
49+
else:
50+
amount = int(num) * int(page)
4851

4952
country = self.get_store_id_for_country(country)
5053
headers = {

scraper_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ def test_country_code_does_not_exist():
4848
scraper = AppStoreScraper()
4949
with pytest.raises(AppStoreException, match="Country code not found for XZ"):
5050
scraper.get_store_id_for_country('xz')
51+
52+
def test_query_multiple_pages():
53+
query = "game"
54+
scraper = AppStoreScraper()
55+
results = set()
56+
for page in range(1,4):
57+
page_results = scraper.get_app_ids_for_query(query, country="us", lang="en", page=page)
58+
if page_results:
59+
[results.add(x) for x in page_results]
60+
assert len(results) > (page-1)*50
61+
print(f"Total results for query {query}: {len(results)}")

0 commit comments

Comments
 (0)