コード例 #1
0
ファイル: ipregex_tests.py プロジェクト: xZise/pywikibot-core
 def _do_ip_test(self, address):
     return ip.is_IP(address)
コード例 #2
0
 def _do_ip_test(self, address):
     return ip.is_IP(address)
コード例 #3
0
    def find_authors(self, page):
        """
        Retrieve main authors of given page.

        @note: userPut() sets current_page therefore we cannot use it.

        @param page: Page object to retrieve main authors
        @type page: pywikibot.Page
        @return: yield tuple of user name and edit quantity
        @rtype: generator
        """
        percent = 0
        if page.namespace() == pywikibot.site.Namespace.MAIN:
            url = ('https://tools.wmflabs.org/wikihistory/dewiki/'
                   'getauthors.php?page_id={0}'.format(page.pageid))
            try:
                r = fetch(url)
            except requests.exceptions.ConnectionError:
                pywikibot.exception()
            else:
                if r.status not in (200, ):
                    pywikibot.warning('wikihistory request status is %d'
                                      % r.status)
                else:
                    pattern = r'>(?P<author>.+?)</a>\s\((?P<percent>\d{1,3})&'
                    for main, main_cnt in re.findall(pattern,
                                                     r.decode('utf-8')):
                        main_cnt = int(main_cnt)
                        percent += main_cnt
                        if ' weitere' in main:
                            break
                        yield main, main_cnt
                        if percent > 50:
                            break

        if percent != 0:
            return

        # A timeout occured or not main namespace, calculate it yourself
        pywikibot.output('No wikihistory data available for %s.\n'
                         'Retrieving revisions.' % page)
        cnt = Counter()

        for rev in page.revisions():
            if is_IP(rev.user):
                continue
            if rev.minor:
                cnt[rev.user] += 0.2
            else:
                cnt[rev.user] += 1

        s = sum(cnt.values())
        s2 = sum(i ** 2 for i in cnt.values())
        n = float(max(len(cnt), 1))
        x_ = s / n
        # avg + stdabw
        limit = max(3, (s2 / n - x_ ** 2) ** 0.5 * 1.5 + x_)

        for main, main_cnt in cnt.most_common(7):
            if main_cnt < limit:
                break
            yield main, main_cnt * 100 / s