本文整理汇总了Python中pywikibot.data.api.Request.submit方法的典型用法代码示例。如果您正苦于以下问题:Python Request.submit方法的具体用法?Python Request.submit怎么用?Python Request.submit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywikibot.data.api.Request
的用法示例。
在下文中一共展示了Request.submit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: review
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def review(site, token, page):
"""Review the latest revision of the given page."""
revid = page.latest_revision_id
request = Request(site=site,
action="review",
token=token,
revid=revid)
request.submit()
示例2: RecentChanges
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def RecentChanges(limit):
limitString = limit
time_format = "%Y-%m-%dT%H:%M:%SZ"
limit = datetime.datetime.fromtimestamp(time.mktime(time.strptime(limitString, time_format)))
current = datetime.datetime.now()
list = set()
params = {
'action' :'query',
'list' :'recentchanges',
'rcprop' :'timestamp|title',
'rclimit' :'100',
'rcnamespace': 0
}
while current > limit:
textDate = current.strftime(time_format)
params['rcstart'] = textDate
req = Request(**params)
qr = req.submit()
try: current = datetime.datetime.fromtimestamp(time.mktime(time.strptime(qr['query-continue']['recentchanges']['rcstart'], time_format)))
except KeyError:
for elem in qr['query']['recentchanges']:
list.add(elem['title'])
break
else:
for elem in qr['query']['recentchanges']:
list.add(elem['title'])
return list
示例3: pageCounter
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def pageCounter(language):
#returns number of entries for a language
params = {
'action' :'expandtemplates',
'text' :'{{PAGESINCAT:%s (indeks)|R}}' % language,
}
req = Request(**params)
qr = req.submit()
print(qr['expandtemplates']['*'])
示例4: flagLastRev
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def flagLastRev(site, revid, comment=''):
token = site.getToken(sysop=False)
params = {
'site': site,
'action': 'review',
'revid': revid,
'token': token,
'flag_accuracy': 1,
'comment': comment,
}
req = Request(**params)
query = req.submit()
示例5: _load_pages
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def _load_pages(self, titles):
"""Load a chunk of pages from the API."""
def _get_rev(page):
try:
return page["revisions"][0]["slots"]["main"]["content"]
except (KeyError, IndexError):
return ""
req = Request(self._bot.site, parameters={
"action": "query", "prop": "revisions", "rvprop": "content",
"rvslots": "main", "formatversion": "2", "titles": "|".join(titles)
})
data = req.submit()
return [(page["title"], _get_rev(page))
for page in data["query"]["pages"]]
示例6: get_orlist
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def get_orlist(site=DEFAULT_SITE, namespace="0|6|10|14|100|828", redirects="nonredirects"):
"""Get list of oldreviewed pages."""
request = Request(site=site,
action="query",
list="oldreviewedpages",
ornamespace=namespace,
orfilterredir=redirects,
orlimit="5000")
result = []
while True:
answer = request.submit()
result += [page["title"] for page in answer["query"]["oldreviewedpages"]]
if "query-continue" in answer:
request["orstart"] = answer["query-continue"]["oldreviewedpages"]["orstart"]
else:
break
return result
示例7: get_pages_categories
# 需要导入模块: from pywikibot.data.api import Request [as 别名]
# 或者: from pywikibot.data.api.Request import submit [as 别名]
def get_pages_categories(pagelist, site=DEFAULT_SITE, limit=500):
"""
For every page from the list get list of categories and return
{page: [categories]}
dictionary.
"""
result = dict.fromkeys(pagelist, [])
kwargs = {
"action": "query",
"prop": "categories",
"cllimit": "5000"
}
for idx in range(0, len(pagelist), limit):
kwargs["titles"] = "|".join(pagelist[idx:idx+limit])
request = Request(site=site, **kwargs)
while True:
answer = request.submit()
# Wikipedia API can return page list in non-canonical form!
# At least when there are two possible canonical forms for one namespace
# (for instance, "Участник" – "Участница" in Russian Wikipedia).
# This query will normalize them and we need to handle it.
denormalize = {}
if "normalized" in answer["query"]:
for fix in answer["query"]["normalized"]:
denormalize[fix["to"]] = fix["from"]
for value in answer["query"]["pages"].values():
title = value["title"]
if title in denormalize:
title = denormalize[title]
if "categories" in value:
cats = [cat["title"] for cat in value["categories"]]
result[title] = result[title] + cats
if "query-continue" in answer:
request["clcontinue"] = answer["query-continue"]["categories"]["clcontinue"]
continue
break
return result