Beispiel #1
0
 def run(self):
     if self.users:
         while True:
             try:
                 data = self.getData()
             except Exception, e:
                 # Print the traceback of the caught exception
                 print e
                 raise
             else:
                 break
         for uj in self.users:
             try:
                 x = data[uj.name()]
             except KeyError:
                 break
             if "missing" in x:
                 break
             uj._editcount = x["editcount"]
             if "groups" in x:
                 uj._groups = x["groups"]
             else:
                 uj._groups = []
             if x["registration"]:
                 uj._registrationTime = pywikibot.parsetime2stamp(x["registration"])
             else:
                 uj._registrationTime = 0
             uj._mailable = "emailable" in x
             uj._blocked = "blockedby" in x
 def run(self):
     if self.users:
         while True:
             try:
                 data = self.getData()
             except Exception, e:
                 # Print the traceback of the caught exception
                 print e
                 raise
             else:
                 break
         for uj in self.users:
             try:
                 x = data[uj.name()]
             except KeyError:
                 break
             if 'missing' in x:
                 break
             uj._editcount = x['editcount']
             if 'groups' in x:
                 uj._groups = x['groups']
             else:
                 uj._groups = []
             if x['registration']:
                 uj._registrationTime = pywikibot.parsetime2stamp(
                     x['registration'])
             else:
                 uj._registrationTime = 0
             uj._mailable = ("emailable" in x)
             uj._blocked = ('blockedby' in x)
Beispiel #3
0
 def run(self):
     if self.users:
         while True:
             try:
                 data = self.getData()
             except Exception, e:
                 # Print the traceback of the caught exception
                 print e
                 raise
             else:
                 break
         for uj in self.users:
             try:
                 x = data[uj.name()]
             except KeyError:
                 break
             if 'missing' in x:
                 break
             uj._editcount = x['editcount']
             if 'groups' in x:
                 uj._groups = x['groups']
             else:
                 uj._groups = []
             if x['registration']:
                 uj._registrationTime = pywikibot.parsetime2stamp(
                     x['registration'])
             else:
                 uj._registrationTime = 0
             uj._mailable = ("emailable" in x)
             uj._blocked = ('blockedby' in x)
Beispiel #4
0
    def contributions(self, limit=500, namespace=[]):
        """ Yield tuples describing this user edits with an upper bound of
        'limit'. Each tuple is composed of a pywikibot.Page object,
        the revision id (int), the edit timestamp and the comment (unicode).
        Pages returned are not guaranteed to be unique.

        @param limit: limit result to this number of pages
        @type limit: int
        @param namespace: only iterate links in these namespaces
        @type namespace: list
        """
        if not self.site().has_api():
            raise NotImplementedError

        params = {
            'action': 'query',
            'list': 'usercontribs',
            'ucuser': self.name(),
            'ucprop': ['ids', 'title', 'timestamp',
                       'comment'],  # 'size','flags'],
            'uclimit': limit,
            'ucdir': 'older',
        }
        if limit > pywikibot.config.special_page_limit:
            params['uclimit'] = pywikibot.config.special_page_limit
            if limit > 5000 and self.site().isAllowed('apihighlimits'):
                params['uclimit'] = 5000
        if namespace:
            params['ucnamespace'] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            pywikibot.output(u'Retrieving %s user contributions from %s...' %
                             (params['uclimit'], self.site()))
            result = query.GetData(params, self.site())
            if 'error' in result:
                pywikibot.output('%s' % result)
                raise pywikibot.Error
            for contrib in result['query']['usercontribs']:
                ts = pywikibot.parsetime2stamp(contrib['timestamp'])
                yield (pywikibot.Page(self.site(),
                                      contrib['title'],
                                      defaultNamespace=contrib['ns']),
                       contrib['revid'], ts, contrib.get('comment', None))
                nbresults += 1
                if nbresults >= limit:
                    break
            if 'query-continue' in result and nbresults < limit:
                params['ucstart'] = result['query-continue']['usercontribs'][
                    'ucstart']
            else:
                break
        return
Beispiel #5
0
    def contributions(self, limit=500, namespace=[]):
        """ Yield tuples describing this user edits with an upper bound of
        'limit'. Each tuple is composed of a pywikibot.Page object,
        the revision id (int), the edit timestamp and the comment (unicode).
        Pages returned are not guaranteed to be unique.

        @param limit: limit result to this number of pages
        @type limit: int
        @param namespace: only iterate links in these namespaces
        @type namespace: list
        """
        if not self.site().has_api():
            raise NotImplementedError

        params = {
            "action": "query",
            "list": "usercontribs",
            "ucuser": self.name(),
            "ucprop": ["ids", "title", "timestamp", "comment"],  # 'size','flags'],
            "uclimit": limit,
            "ucdir": "older",
        }
        if limit > pywikibot.config.special_page_limit:
            params["uclimit"] = pywikibot.config.special_page_limit
            if limit > 5000 and self.site().isAllowed("apihighlimits"):
                params["uclimit"] = 5000
        if namespace:
            params["ucnamespace"] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            pywikibot.output(u"Retrieving %s user contributions from %s..." % (params["uclimit"], self.site()))
            result = query.GetData(params, self.site())
            if "error" in result:
                pywikibot.output("%s" % result)
                raise pywikibot.Error
            for contrib in result["query"]["usercontribs"]:
                ts = pywikibot.parsetime2stamp(contrib["timestamp"])
                yield (
                    pywikibot.Page(self.site(), contrib["title"], defaultNamespace=contrib["ns"]),
                    contrib["revid"],
                    ts,
                    contrib.get("comment", None),
                )
                nbresults += 1
                if nbresults >= limit:
                    break
            if "query-continue" in result and nbresults < limit:
                params.update(result["query-continue"]["usercontribs"])
            else:
                break
        return
Beispiel #6
0
    def contributions(self, limit=500, namespace=[]):
        """ Yield tuples describing this user edits with an upper bound of
        'limit'. Each tuple is composed of a pywikibot.Page object,
        the revision id (int), the edit timestamp and the comment (unicode).
        Pages returned are not guaranteed to be unique.

        @param limit: limit result to this number of pages
        @type limit: int
        @param namespace: only iterate links in these namespaces
        @type namespace: list
        """
        if not self.site().has_api():
            raise NotImplementedError

        params = {
            'action': 'query',
            'list': 'usercontribs',
            'ucuser': self.name(),
            'ucprop': ['ids','title','timestamp','comment'],# 'size','flags'],
            'uclimit': limit,
            'ucdir': 'older',
        }
        if limit > pywikibot.config.special_page_limit:
            params['uclimit'] = pywikibot.config.special_page_limit
            if limit > 5000 and self.site().isAllowed('apihighlimits'):
                params['uclimit'] = 5000
        if namespace:
            params['ucnamespace'] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            pywikibot.output(u'Retrieving %s user contributions from %s...'
                             % (params['uclimit'], self.site()))
            result = query.GetData(params, self.site())
            if 'error' in result:
                pywikibot.output('%s' % result)
                raise pywikibot.Error
            for contrib in result['query']['usercontribs']:
                ts = pywikibot.parsetime2stamp(contrib['timestamp'])
                yield (pywikibot.Page(self.site(), contrib['title'],
                                      defaultNamespace=contrib['ns']),
                       contrib['revid'], ts, contrib.get('comment', None)
                )
                nbresults += 1
                if nbresults >= limit:
                    break
            if 'query-continue' in result and nbresults < limit:
                params['ucstart'] = result['query-continue']['usercontribs']['ucstart']
            else:
                break
        return
Beispiel #7
0
    def contributions(self, limit=500, namespace=[]):
        """ Yields pages that the user has edited, with an upper bound of ``limit''.
        Pages returned are not guaranteed to be unique
        (straight Special:Contributions parsing, in chunks of 500 items)."""
        if not self.site().has_api():
            raise NotImplementedError
        # please stay this in comment until the regex is fixed
        #    for pg, oldid, date, comment in self._ContributionsOld(limit):
        #       yield pg, oldid, date, comment
        #    return

        params = {
            "action": "query",
            "list": "usercontribs",
            "ucuser": self.name(),
            "ucprop": ["ids", "title", "timestamp", "comment"],  # 'size','flags'],
            "uclimit": int(limit),
            "ucdir": "older",
        }
        if limit > wikipedia.config.special_page_limit:
            params["uclimit"] = wikipedia.config.special_page_limit
            if limit > 5000 and self.site().isAllowed("apihighlimits"):
                params["uclimit"] = 5000
        if namespace:
            params["ucnamespace"] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            result = query.GetData(params, self.site())
            if "error" in result:
                wikipedia.output("%s" % result)
                raise wikipedia.Error
            for c in result["query"]["usercontribs"]:
                yield (
                    wikipedia.Page(self.site(), c["title"], defaultNamespace=c["ns"]),
                    c["revid"],
                    wikipedia.parsetime2stamp(c["timestamp"]),
                    c["comment"],
                )
                nbresults += 1
                if nbresults >= limit:
                    break
            if "query-continue" in result and nbresults < limit:
                params["ucstart"] = result["query-continue"]["usercontribs"]["ucstart"]
            else:
                break
        return
Beispiel #8
0
    def contributions(self, limit=500, namespace=[]):
        """ Yields pages that the user has edited, with an upper bound of ``limit''.
        Pages returned are not guaranteed to be unique
        (straight Special:Contributions parsing, in chunks of 500 items)."""
        if not self.site().has_api():
            raise NotImplementedError
        # please stay this in comment until the regex is fixed
        #    for pg, oldid, date, comment in self._ContributionsOld(limit):
        #       yield pg, oldid, date, comment
        #    return

        params = {
            'action': 'query',
            'list': 'usercontribs',
            'ucuser': self.name(),
            'ucprop': ['ids', 'title', 'timestamp',
                       'comment'],  # 'size','flags'],
            'uclimit': int(limit),
            'ucdir': 'older',
        }
        if limit > wikipedia.config.special_page_limit:
            params['uclimit'] = wikipedia.config.special_page_limit
            if limit > 5000 and self.site().isAllowed('apihighlimits'):
                params['uclimit'] = 5000
        if namespace:
            params['ucnamespace'] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            result = query.GetData(params, self.site())
            if 'error' in result:
                wikipedia.output('%s' % result)
                raise wikipedia.Error
            for c in result['query']['usercontribs']:
                yield (wikipedia.Page(self.site(),
                                      c['title'],
                                      defaultNamespace=c['ns']), c['revid'],
                       wikipedia.parsetime2stamp(c['timestamp']), c['comment'])
                nbresults += 1
                if nbresults >= limit:
                    break
            if 'query-continue' in result and nbresults < limit:
                params['ucstart'] = result['query-continue']['usercontribs'][
                    'ucstart']
            else:
                break
        return
Beispiel #9
0
    def contributions(self, limit = 500, namespace = []):
        """ Yields pages that the user has edited, with an upper bound of ``limit''.
        Pages returned are not guaranteed to be unique
        (straight Special:Contributions parsing, in chunks of 500 items)."""
        if not self.site().has_api():
            raise NotImplementedError
        # please stay this in comment until the regex is fixed
        #    for pg, oldid, date, comment in self._ContributionsOld(limit):
        #       yield pg, oldid, date, comment
        #    return

        params = {
            'action': 'query',
            'list': 'usercontribs',
            'ucuser': self.name(),
            'ucprop': ['ids','title','timestamp','comment'],# 'size','flags'],
            'uclimit': int(limit),
            'ucdir': 'older',
        }
        if limit > wikipedia.config.special_page_limit:
            params['uclimit'] = wikipedia.config.special_page_limit
            if limit > 5000 and self.site().isAllowed('apihighlimits'):
                params['uclimit'] = 5000
        if namespace:
            params['ucnamespace'] = namespace
        # An user is likely to contribute on several pages,
        # keeping track of titles
        nbresults = 0
        while True:
            result = query.GetData(params, self.site())
            if 'error' in result:
                wikipedia.output('%s' % result)
                raise wikipedia.Error
            for c in result['query']['usercontribs']:
                yield (wikipedia.Page(self.site(), c['title'], defaultNamespace=c['ns']),
                  c['revid'],
                  wikipedia.parsetime2stamp(c['timestamp']),
                  c['comment']
                )
                nbresults += 1
                if nbresults >= limit:
                    break
            if 'query-continue' in result and nbresults < limit:
                params['ucstart'] = result['query-continue']['usercontribs']['ucstart']
            else:
                break
        return
Beispiel #10
0
    def load_whitelist(self):
        # Check for a more recent version after 5 minutes
        if self.whitelist_load_ts and (
                (time.time() - self.whitelist_load_ts) < 300):
            if pywikibot.verbose:
                pywikibot.output(u'Whitelist not stale yet')
            return

        whitelist_page = pywikibot.Page(pywikibot.getSite(),
                                        self.whitelist_pagename)

        if not self.whitelist:
            pywikibot.output(u'Loading %s' % self.whitelist_pagename)

        try:
            if self.whitelist_ts:
                # check for a more recent version
                h = whitelist_page.getVersionHistory(forceReload=True,
                                                     revCount=1)
                last_edit_ts = pywikibot.parsetime2stamp(h[0][1])
                if last_edit_ts == self.whitelist_ts:
                    # As there hasn't been any changed to the whitelist
                    # it has been effectively reloaded 'now'
                    self.whitelist_load_ts = time.time()
                    if pywikibot.verbose:
                        pywikibot.output(u'Whitelist not modified')
                    return

            if self.whitelist:
                pywikibot.output(u'Reloading whitelist')

            # Fetch whitelist
            wikitext = whitelist_page.get()
            # Parse whitelist
            self.whitelist = self.parse_page_tuples(wikitext, self.user)
            # Record timestamp
            self.whitelist_ts = whitelist_page.editTime()
            self.whitelist_load_ts = time.time()
        except Exception as e:
            # cascade if there isnt a whitelist to fallback on
            if not self.whitelist:
                raise
            pywikibot.error(u'%s' % e)
Beispiel #11
0
    def load_whitelist(self):
        # Check for a more recent version after 5 minutes
        if self.whitelist_load_ts and (
            (time.time() - self.whitelist_load_ts) < 300):
            if pywikibot.verbose:
                pywikibot.output(u'Whitelist not stale yet')
            return

        whitelist_page = pywikibot.Page(pywikibot.getSite(),
                                        self.whitelist_pagename)

        if not self.whitelist:
            pywikibot.output(u'Loading %s' % self.whitelist_pagename)

        try:
            if self.whitelist_ts:
                # check for a more recent version
                h = whitelist_page.getVersionHistory(forceReload=True,
                                                     revCount=1)
                last_edit_ts = pywikibot.parsetime2stamp(h[0][1])
                if last_edit_ts == self.whitelist_ts:
                    # As there hasn't been any changed to the whitelist
                    # it has been effectively reloaded 'now'
                    self.whitelist_load_ts = time.time()
                    if pywikibot.verbose:
                        pywikibot.output(u'Whitelist not modified')
                    return

            if self.whitelist:
                pywikibot.output(u'Reloading whitelist')

            # Fetch whitelist
            wikitext = whitelist_page.get()
            # Parse whitelist
            self.whitelist = self.parse_page_tuples(wikitext, self.user)
            # Record timestamp
            self.whitelist_ts = whitelist_page.editTime()
            self.whitelist_load_ts = time.time()
        except Exception as e:
            # cascade if there isnt a whitelist to fallback on
            if not self.whitelist:
                raise
            pywikibot.error(u'%s' % e)