-
Notifications
You must be signed in to change notification settings - Fork 103
/
api.py
92 lines (69 loc) · 2.96 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
"""
play_scraper.api
:copyright: (c) 2016 Daniel Liu.
:license: MIT, see LICENSE for more details.
"""
from . import scraper
def details(app_id):
"""Sends a GET request to the app's info page, parses the app's details, and
returns them as a dict.
:param app_id: the app to retrieve details from, e.g. 'com.nintendo.zaaa'
:return: a dictionary of app details
"""
s = scraper.PlayScraper()
return s.details(app_id)
def collection(collection, category=None, **kwargs):
"""Sends a POST request to the collection url, gets each app's details, and
returns them in a list.
List of acceptable collections and categories can be found in settings.
:param collection: the collection ID as a string.
:param category: the category ID as a string.
:param results: the number of app results to retrieve
:param page: the page number, calculates collection start index. is limited
to page * results <= 500
:param age: an age range to filter by (only for FAMILY categories)
:param detailed: if True, sends request per app for full detail
:return: a list of app dictionaries
"""
s = scraper.PlayScraper()
return s.collection(collection, category, **kwargs)
def developer(developer, **kwargs):
"""Sends a POST request to the developer's page, extracts their apps' basic
info, and returns them in a list.
:param developer: developer name to retrieve apps from, e.g. 'Disney'
:param results: the number of app results to retrieve
:param page: the page number to retrieve
:param detailed: if True, sends request per app for full detail
:return: a list of app dictionaries
"""
s = scraper.PlayScraper()
return s.developer(developer, **kwargs)
def suggestions(query):
"""Sends a GET request to the Play Store's suggestion API and returns up to
five autocompleted suggested query strings in a list.
:param query: the query string to get autocomplete suggestions
:return: a list of suggestion strings
"""
s = scraper.PlayScraper()
return s.suggestions(query)
def search(query, **kwargs):
"""Sends a POST request and retrieves a list of applications matching
the query term(s).
:param query: search query term(s) to retrieve matching apps
:param page: the page number to retrieve; max is 12
:param detailed: if True, sends request per app for its full detail
:return: a list of apps matching search terms
"""
s = scraper.PlayScraper()
return s.search(query, **kwargs)
def similar(app_id, **kwargs):
"""Sends a POST request and retrieves a list of applications similar to
the specified app.
:param app_id: the app to retrieve details from, e.g. 'com.nintendo.zaaa'
:param results: the number of apps to retrieve at a time.
:param detailed: if True, sends request per app for its full detail
:return: a list of similar apps
"""
s = scraper.PlayScraper()
return s.similar(app_id, **kwargs)