当前位置: 首页>>代码示例>>Python>>正文


Python api.Request类代码示例

本文整理汇总了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
开发者ID:alkamid,项目名称:wiktionary,代码行数:28,代码来源:klasa.py

示例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()
开发者ID:Facenapalm,项目名称:NapalmBot,代码行数:8,代码来源:revredirs.py

示例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']['*'])
开发者ID:alkamid,项目名称:wiktionary,代码行数:9,代码来源:klasa.py

示例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()
开发者ID:alkamid,项目名称:wiktionary,代码行数:14,代码来源:klasa.py

示例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))
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:7,代码来源:dry_api_tests.py

示例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"]]
开发者ID:harej,项目名称:reports_bot,代码行数:16,代码来源:new_discussions.py

示例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
开发者ID:Facenapalm,项目名称:NapalmBot,代码行数:17,代码来源:validstats.py

示例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))
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:9,代码来源:dry_api_tests.py

示例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)
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:9,代码来源:dry_api_tests.py

示例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)
开发者ID:Exal117,项目名称:pywikibot-core,代码行数:9,代码来源:dry_api_tests.py

示例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)
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:10,代码来源:dry_api_tests.py

示例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
开发者ID:Facenapalm,项目名称:NapalmBot,代码行数:39,代码来源:sort_unrev_files.py

示例13: create_simple

 def create_simple(cls, **kwargs):
     """Skip CachedRequest implementation."""
     return _original_Request.create_simple(**kwargs)
开发者ID:Annie201,项目名称:pywikibot-core,代码行数:3,代码来源:utils.py

示例14: __init__

 def __init__(self, *args, **kwargs):
     """Constructor."""
     _original_Request.__init__(self, *args, **kwargs)
开发者ID:Annie201,项目名称:pywikibot-core,代码行数:3,代码来源:utils.py

示例15: __init__

 def __init__(self, *args, **kwargs):
     _original_Request.__init__(self, *args, **kwargs)
开发者ID:rubin16,项目名称:pywikibot-core,代码行数:2,代码来源:utils.py


注:本文中的pywikibot.data.api.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。