예제 #1
0
for comment in tb.stream.comments():
    print(comment.parent_id, comment.author, "says", comment.body)
    if '!localray' in comment.body.lower() and comment.author != 'localray':
        print("*" * 20, "\nlocalray is here to answer your questions\n",
              "*" * 20)
        if comment.id not in replied:
            print("new comment")
            reply = comment.reply(respond(comment))
            if 'wordcloud' in reply.body:
                final_url = re.search("(?P<url>https?://[^\s]+)",
                                      comment.body).group("url")
                try:

                    reply.reply(
                        f"[Here is the worldcloud for that post's comments]({create_wordcloud(final_url)})"
                    )

                except Exception as e:
                    #raise e
                    reply.reply(
                        ray.raysay(
                            f"Couldn't do it this time, but here's a piece of advice",
                            quote=True))

                final_url = None
            replied.append(comment.id)
        with open('replied.txt', 'w') as f:
            f.writelines([f"{x}\n" for x in replied])
        # fire off the make decision function, pass comment
        pass
    try:
        new_rows = df.merge(
            last_df, how='outer',
            indicator=True).loc[lambda x: x['_merge'] == 'left_only']
    except pd.errors.MergeError:
        new_rows = df

    print(new_rows.shape[0], " new events retreived")
    for row in new_rows.itertuples():
        we = 1 - row.we
        if we - last_we > .15:
            print(row.playDesc, last_we, we)
            reply_que.append(
                ray.raysay(
                    f"{row.playDesc}\n Woo!! our chances of winning are now {we:.2%}"
                ))
            last_we = we
        if we - last_we < -.15:
            print(row.playDesc, last_we, we)
            reply_que.append(
                ray.raysay(
                    f"{row.playDesc}\n Oh No!! our chances of winning are now {we:.2%}"
                ))
            last_we = we
    if len(reply_que) > 0:
        next_reply = reply_que.pop(0)
        print(next_reply)
        gdt_thread.reply(next_reply)
    last_df = df
    time.sleep(seconds_to_wait)