Пример #1
0
def main():
    gen = lrepeat.repeat(site, site.recentchanges, lambda x: x["revid"], 60,
                         showRedirects=False, changetype=["edit", "new"],
                         showBot=False, namespaces=[0],
                         start=site.getcurrenttime() - ltime.td(hours=1))
    for rev in gen:
        try:
            check(rev)
        except:
            wp.error()
            pass
Пример #2
0
def main():
    user = {}
    seen = set()
    start = site.getcurrenttime()
    delta = wp.handlearg("delta", args)
    if delta:
        start -= ltime.td(int(delta))
    config = wp.ReadCode(wp.Page(u"ผู้ใช้:Nullzerobot/ปูมการละเมิด"), "config")
    while True:
        oldConfig = dict(config.data)
        config.load()
        if oldConfig != config.data:
            pywikibot.output(">>> reload new config!")
        for i in config.data:
            data = config.data[i]
            for ab in site.abuselog(reverse=True, abuseid=i, start=start, as_group='sysop'):
                if (ab["id"]) in seen:
                    continue
                seen.add(ab["id"])
                pywikibot.output("filter: %s\t\tuser: %s\t\ttime: %s" %
                                (i, ab["user"].ljust(16), ab["timestamp"]))
                userobj = wp.User(ab["user"])
                if userobj.editCount() >= 5000:
                    continue
                if userobj.name() not in user:
                    user[userobj.name()] = {}
                if i not in user[userobj.name()]:
                    user[userobj.name()][i] = deque()
                deq = user[userobj.name()][i]
                deq.append(pywikibot.Timestamp.fromISOformat(ab["timestamp"]))
                now = site.getcurrenttime()
                while deq and ((now - deq[0]).seconds >= data["checkDuration"]):
                    deq.popleft()
                pywikibot.output(list(deq))
                if len(deq) >= data["threshold"]:
                    process(userobj, data, ab)
                    deq.clear()
        if delta:
            break
        ltime.sleep(60)
        start = max(start, site.getcurrenttime() - ltime.td(seconds=120))
Пример #3
0
def repeat(site, func, keyfunc, wait, **kwargs):
    start = None
    if "start" in kwargs:
        start = kwargs["start"]
        del kwargs["start"]
    start = start or site.getcurrenttime()
    seen = set()
    while True:
        gen = func(start=start, reverse=True, **kwargs)
        for item in gen:
            key = keyfunc(item)
            if key not in seen:
                seen.add(key)
                yield item

        ltime.sleep(wait)
        start = max(start, site.getcurrenttime() - ltime.td(seconds=2*wait))
Пример #4
0
 def remaining():
     remainingItems = self.pool.qsize() - 1
         # -1 because we added a None element to stop the queue
     remainingSeconds = ltime.td(seconds=remainingItems)
     return (remainingItems, remainingSeconds)