本文整理汇总了Python中pywikibot.data.api.Request类的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RecentChanges
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
示例2: review
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()
示例3: pageCounter
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
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: test_mime_file_payload
def test_mime_file_payload(self):
"""Test Request._generate_MIME_part loads binary as binary."""
local_filename = os.path.join(_images_dir, "MP_sounds.png")
with open(local_filename, "rb") as f:
file_content = f.read()
submsg = Request._generate_MIME_part("file", file_content, ("image", "png"), {"filename": local_filename})
self.assertEqual(file_content, submsg.get_payload(decode=True))
示例6: _load_pages
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"]]
示例7: get_orlist
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
示例8: test_mime_file_payload
def test_mime_file_payload(self):
"""Test Request._generate_MIME_part loads binary as binary."""
local_filename = join_images_path('MP_sounds.png')
with open(local_filename, 'rb') as f:
file_content = f.read()
submsg = Request._generate_MIME_part(
'file', file_content, ('image', 'png'),
{'filename': local_filename})
self.assertEqual(file_content, submsg.get_payload(decode=True))
示例9: test_mime_file_container
def test_mime_file_container(self):
"""Test Request._build_mime_request encodes binary."""
local_filename = os.path.join(_images_dir, "MP_sounds.png")
with open(local_filename, "rb") as f:
file_content = f.read()
body = Request._build_mime_request(
{}, {"file": (file_content, ("image", "png"), {"filename": local_filename})}
)[1]
self.assertNotEqual(body.find(file_content), -1)
示例10: test_mime_file_container
def test_mime_file_container(self):
local_filename = os.path.join(_data_dir, 'MP_sounds.png')
with open(local_filename, 'rb') as f:
file_content = f.read()
body = Request._build_mime_request({}, {
'file': (file_content, ('image', 'png'),
{'filename': local_filename})
})[1]
self.assertNotEqual(body.find(file_content), -1)
示例11: test_mime_file_container
def test_mime_file_container(self):
"""Test Request._build_mime_request encodes binary."""
local_filename = join_images_path('MP_sounds.png')
with open(local_filename, 'rb') as f:
file_content = f.read()
body = Request._build_mime_request({}, {
'file': (file_content, ('image', 'png'),
{'filename': local_filename})
})[1]
self.assertNotEqual(body.find(file_content), -1)
示例12: get_pages_categories
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
示例13: create_simple
def create_simple(cls, **kwargs):
"""Skip CachedRequest implementation."""
return _original_Request.create_simple(**kwargs)
示例14: __init__
def __init__(self, *args, **kwargs):
"""Constructor."""
_original_Request.__init__(self, *args, **kwargs)
示例15: __init__
def __init__(self, *args, **kwargs):
_original_Request.__init__(self, *args, **kwargs)