Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F31616724
apitest.py
William_Avery
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
William_Avery
Feb 14 2020, 9:17 PM
2020-02-14 21:17:19 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
apitest.py
View Options
import
requests
apiurl
=
"http://en.wikipedia.org/w/api.php"
params
=
{
'action'
:
'query'
,
'format'
:
'json'
,
'list'
:
'categorymembers'
,
'cmtitle'
:
'Category:Gastropods_described_in_1999'
,
'cmtype'
:
'page'
,
'cmlimit'
:
300
,
'cmsort'
:
'sortkey'
,
'cmstartsortkeyprefix'
:
'H'
,
'cmendsortkeyprefix'
:
'I'
,
}
# Request with cmlimit big enough to accomodate all expected results
rsponse
=
requests
.
get
(
url
=
apiurl
,
params
=
params
)
print
(
'###### Everything beginning with H in one gulp ######'
)
print
(
rsponse
.
json
())
# reduce cmlimit and iterate with continue parameters
print
(
'###### Using cmlimit=20 ######'
)
params
[
'cmlimit'
]
=
20
complete
=
''
iteration
=
1
while
complete
==
''
:
rsponse
=
requests
.
get
(
url
=
apiurl
,
params
=
params
)
json
=
rsponse
.
json
()
print
(
'>>>> iteration='
+
str
(
iteration
)
+
' <<<<'
)
print
(
json
)
if
(
json
.
get
(
'continue'
)):
for
contkey
,
value
in
json
[
'continue'
]
.
items
():
params
[
contkey
]
=
value
else
:
complete
=
'complete'
iteration
=
iteration
+
1
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8320619
Default Alt Text
apitest.py (1 KB)
Attached To
Mode
T245310: API calls ignoring cmendsortkeyprefix parameter when continue parameter is present
Attached
Detach File
Event Timeline
Log In to Comment