Beispiel #1
0
def run(func):
    global info
    if not info["main"]:
        return
    task = ReadCode(Page(u"User:Nullzerobot/แผงควบคุม"), "task")
    task.load()

    if info["taskid"] not in task.data:
        func()
        return

    if not task.data[info["taskid"]]:
        ltime.sleep(3 * 60 * 60)  # sleep 3 hours
        return

    thread = lthread.EThread(target=func)
    thread.daemon = True
    thread.start()

    try:
        while True:
            for i in xrange(12):
                if not thread.isAlive():
                    break
                ltime.sleep(5)

            task.load()
            if not (task.data[info["taskid"]] and thread.isAlive()):
                break
    except:
        error()

    if thread.error:
        raise RuntimeError
Beispiel #2
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))
Beispiel #3
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))