Exemple #1
0
def current_match_new_action(matches):
    def cmp(om, nm):
        return len(nm) and (
            len(om) == 0 or
            len(nm[0]["home_team_events"]) != len(om[0]["home_team_events"]) or
            len(nm[0]["away_team_events"]) != len(om[0]["away_team_events"]))

    context.add_event(
        ModuleEvent(func=partial(
            lambda url: json.loads(urlopen(url).read().decode()),
            API_URL % "matches/current?by_date=DESC"),
                    cmp=partial(cmp, matches),
                    call=current_match_new_action,
                    interval=30))

    for match in matches:
        if is_valid(match):
            events = sort_events(match["home_team"], match["away_team"],
                                 match["home_team_events"],
                                 match["away_team_events"])
            msg = "Match %s vs. %s ; score %s - %s" % (
                match["home_team"]["country"], match["away_team"]["country"],
                match["home_team"]["goals"], match["away_team"]["goals"])

            if len(events) > 0:
                msg += " ; à la " + txt_event(events[0])

            for n in context.data.getChilds():
                context.send_response(n["server"],
                                      Response(msg, channel=n["channel"]))
Exemple #2
0
def fini(name, evt):
    context.send_response(
        evt._server,
        Response("%s arrivé à échéance." % name,
                 channel=evt._channel,
                 nick=evt.creator))
    evt._evt = None
    del context.data[name]
    context.save()
Exemple #3
0
 def bonneannee():
     txt = "Bonne année %d !" % yrn
     print(txt)
     if context.config and context.config.hasNode("sayon"):
         for sayon in context.config.getNodes("sayon"):
             if "hostid" not in sayon or "channel" not in sayon:
                 print("Error: missing hostif or channel")
                 continue
             srv = sayon["hostid"]
             chan = sayon["channel"]
             context.send_response(srv, Response(txt, chan))
Exemple #4
0
def _fini(to_server, to_channel, lastcheck, group, server):
    print("fini called")
    _newevt(to_server=to_server, to_channel=to_channel, group=group, lastcheck=datetime.now(), server=server)
    n = 0
    for art in whatsnew(lastcheck, group, **server):
        n += 1
        if n > 10:
            continue
        context.send_response(to_server, format_article(art, channel=to_channel))
    if n > 10:
        context.send_response(to_server, Response("... and %s others news" % (n - 10), channel=to_channel))
Exemple #5
0
def current_match_new_action(matches, osef):
    def cmp(om, nm):
        return len(nm) and (len(om) == 0 or len(nm[0]["home_team_events"]) != len(om[0]["home_team_events"]) or len(nm[0]["away_team_events"]) != len(om[0]["away_team_events"]))
    context.add_event(ModuleEvent(func=lambda url: json.loads(urlopen(url).read().decode()), func_data=API_URL % "matches/current?by_date=DESC", cmp=cmp, call=current_match_new_action, interval=30))

    for match in matches:
        if is_valid(match):
            events = sort_events(match["home_team"], match["away_team"], match["home_team_events"], match["away_team_events"])
            msg = "Match %s vs. %s ; score %s - %s" % (match["home_team"]["country"], match["away_team"]["country"], match["home_team"]["goals"], match["away_team"]["goals"])

            if len(events) > 0:
                msg += " ; à la " + txt_event(events[0])

            for n in context.data.getChilds():
                context.send_response(n["server"], Response(msg, channel=n["channel"]))
Exemple #6
0
def _ticker(to_server, to_channel, **kwargs):
    global last_seen
    context.add_event(
        ModuleEvent(call=partial(_ticker, to_server, to_channel, **kwargs),
                    interval=42))
    last = getJSON("https://ohsnap.p0m.fr/api/images/last")
    if last["hash"] != last_seen:
        if last_seen is not None:
            context.send_response(
                to_server,
                Response(
                    "Nouveau snap de {author} : https://ohsnap.p0m.fr/{hash}".
                    format(**last),
                    channel=to_channel))
        last_seen = last["hash"]
Exemple #7
0
def _ticker(to_server, to_channel, group, server):
    _newevt(to_server=to_server,
            to_channel=to_channel,
            group=group,
            server=server)
    n = 0
    for art in whatsnew(group, **server):
        n += 1
        if n > 10:
            continue
        context.send_response(to_server, format_article(art,
                                                        channel=to_channel))
    if n > 10:
        context.send_response(
            to_server,
            Response("... and %s others news" % (n - 10), channel=to_channel))
Exemple #8
0
def _fini(to_server, to_channel, lastcheck, group, server):
    print("fini called")
    _newevt(to_server=to_server,
            to_channel=to_channel,
            group=group,
            lastcheck=datetime.now(),
            server=server)
    n = 0
    for art in whatsnew(lastcheck, group, **server):
        n += 1
        if n > 10:
            continue
        context.send_response(to_server, format_article(art,
                                                        channel=to_channel))
    if n > 10:
        context.send_response(
            to_server,
            Response("... and %s others news" % (n - 10), channel=to_channel))
Exemple #9
0
def fini(d, strend):
    context.send_response(strend["server"], Response("%s arrivé à échéance." % strend["name"], channel=strend["channel"], nick=strend["proprio"]))
    context.data.delChild(context.data.index[strend["name"]])
    context.save()
Exemple #10
0
def fini(name, evt):
    context.send_response(evt._server, Response("%s arrivé à échéance." % name, channel=evt._channel, nick=evt.creator))
    evt._evt = None
    del context.data[name]
    context.save()