Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P7506
Pywikibot api_query sample
Active
Public
Actions
Authored by
Framawiki
on Sep 1 2018, 9:26 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
Pywikibot
Referenced Files
F25582241: Pywikibot api_query sample
Sep 1 2018, 9:26 AM
2018-09-01 09:26:19 (UTC+0)
Subscribers
None
import
pywikibot
from
pywikibot.data
import
api
def
api_query
(
params
,
lang
=
'fr'
,
wiki
=
'wikipedia'
):
query
=
api
.
Request
(
site
=
pywikibot
.
Site
(
lang
,
wiki
),
parameters
=
params
)
datas
=
query
.
submit
()
return
datas
# and to use it as a page generator
# code taken on https://github.com/Toto-Azero/Wikipedia
def
creation_log
(
start
,
end
):
"""
query the recent change for creation between the timestamp in parameter
arguments:
start -- time stamp of first creation (format YYYY-MM-DDTHH:MM:SSZ)"
end -- time stamp of last creation (format YYYY-MM-DDTHH:MM:SSZ)"
result:
list of the creation events occuring between the timestamp
"""
params
=
{
'action'
:
'query'
,
'list'
:
'recentchanges'
,
'rctype'
:
'new'
,
'rctag'
:
'contenttranslation'
,
'rcprop'
:
'title|comment|timestamp|user'
,
'rcstart'
:
end
,
'rcend'
:
start
,
'rclimit'
:
'max'
,
}
all_done
=
False
while
not
all_done
:
if
all_done
:
break
datas
=
api_query
(
params
)
if
not
datas
:
break
data
=
datas
[
'query'
][
'recentchanges'
]
for
d
in
data
:
yield
d
if
'query-continue'
in
datas
:
if
'recentchanges'
in
datas
[
'query-continue'
]:
params
[
'rccontinue'
]
=
datas
[
'query-continue'
][
'recentchanges'
][
'rccontinue'
]
else
:
all_done
=
True
for
i
,
page
in
enumerate
(
creation_log
(
start
,
end
),
1
):
xxx
Event Timeline
Framawiki
created this paste.
Sep 1 2018, 9:26 AM
2018-09-01 09:26:19 (UTC+0)
Log In to Comment