Ejemplo n.º 1
0
def chat_count(chatroom, verbose=False):
    global i
    i = 0
    chan = "#" + chatroom
    nick = get_username()
    PASS = get_password()
    sock = socket.socket()
    sock.connect(("irc.twitch.tv", default_port))
    sock.send("PASS " + PASS + "\r\n")
    sock.send("USER " + nick + " 0 * :" + nick + "\r\n")
    sock.send("NICK " + nick + "\r\n")
    full_msg = ""
    while 1:
        sock.send("JOIN " + chan + "\r\n")
        data = removeNonAscii(sock.recv(1024))
        i += 1
        if data[0:4] == "PING":
            sock.send(data.replace("PING", "PONG"))
            continue
        full_msg += data  #if you keep requesting to JOIN the channel, it will continue returning
        #more and more names until "End of /NAMES list"
        if verbose:
            print data
        if ":End of /NAMES list" in data:  #do we end the search?
            if verbose:
                print "returning (\"End of /NAMES list\") due to:"
                print data
            return count_users(full_msg)
        if ":jtv MODE #" in data:
            if verbose:
                print "returning (FOUND MODE) due to:"
                print data
            return count_users(full_msg)
        if "366 " + nick in data:  #status code for ending the stream of names
            if verbose:
                print "returning (366) due to:"
                print data
            return count_users(full_msg)
        if False and "PRIVMSG" in data:  #privmsg's only come in after the names list
            if verbose:
                print "returning (PRIVMSG) due to:"
                print data
            return count_users(full_msg)
Ejemplo n.º 2
0
def chat_count(chatroom, verbose=False):
    global i
    i = 0
    chan = "#" + chatroom
    nick = get_username()
    PASS = get_password()
    sock = socket.socket()
    sock.connect(("irc.twitch.tv", default_port))
    sock.send("PASS " + PASS + "\r\n")
    sock.send("USER " + nick + " 0 * :" + nick + "\r\n")
    sock.send("NICK " + nick + "\r\n")
    full_msg = ""
    while 1:
       sock.send("JOIN "+chan+"\r\n")
       data = removeNonAscii(sock.recv(1024))
       i+=1
       if data[0:4] == "PING":
          sock.send(data.replace("PING", "PONG"))
          continue
       full_msg += data #if you keep requesting to JOIN the channel, it will continue returning 
                        #more and more names until "End of /NAMES list"
       if verbose:
           print data
       if ":End of /NAMES list" in data: #do we end the search?
           if verbose:
               print "returning (\"End of /NAMES list\") due to:"
               print data
           return count_users(full_msg)
       if ":jtv MODE #" in data:
           if verbose:
               print "returning (FOUND MODE) due to:"
               print data
           return count_users(full_msg)
       if "366 " + nick in data: #status code for ending the stream of names
           if verbose:
               print "returning (366) due to:"
               print data
           return count_users(full_msg)
       if False and "PRIVMSG" in data: #privmsg's only come in after the names list
           if verbose:
               print "returning (PRIVMSG) due to:"
               print data
           return count_users(full_msg)
def search_all_games():
    try:
        topreq = requests.get("https://api.twitch.tv/kraken/games/top")
        while topreq.status_code != 200:
            topreq = requests.get("https://api.twitch.tv/kraken/games/top")
        topdata = topreq.json()
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        print "oh. caught error getting the games list."
        search_all_games()
        return
    for i in range(0, len(topdata["top"])):
        game = removeNonAscii(topdata["top"][i]["game"]["name"])
        print "__" + game + "__",
        print "(tweetmode off)" if not tweetmode else ""
        ratio = game_ratio(game)
        print
        print "Average ratio for " + game + ": %0.3f" % ratio
        print
        print
def search_all_games():
    global global_sum
    try:
        topreq = requests.get("https://api.twitch.tv/kraken/games/top?limit=" + str(num_games), headers={"Client-ID": CLIENT_ID})
        while topreq.status_code != 200:
            print "trying to get top games..."
            topreq = requests.get("https://api.twitch.tv/kraken/games/top?limit=" + str(num_games), headers={"Client-ID": CLIENT_ID})
        topdata = topreq.json()
    except requests.exceptions.ConnectionError:
        print "connection error trying to get the game list. recursing :)))"
        return search_all_games
    except ValueError:
        print "nope. recursing. ~287 twitch_chatters.py"
        search_all_games()
    for i in range(0,len(topdata['top'])):
        game = removeNonAscii(topdata['top'][i]['game']['name'])
        print "__" + game + "__", 
        print "(tweetmode off)" if not tweetmode else ""
        prev_suspicious = suspicious[:] #make a duplicate of suspicious before things are added to the new suspicious list
        ratio = game_ratio(game) #does remove elements from suspicious and puts them into confirmed
        for item in suspicious:
            if item.game == game and item in prev_suspicious:
                newconfirmed = [i for i in confirmed if i.game == game and item.user == i.user]
                if newconfirmed != []:
                    suspicious.remove(item)
                    print item.user[10:], "was found to have stopped botting", game + "!",
                    print " removing from suspicious list!"
                else:
                    suspicious.remove(item)
        print
        print "Average ratio for " + game + ": %0.3f" %ratio
        print
        print "Total global ratio: %0.3f" %(global_sum / float(global_cnt))
        print
        print "We are suspicious of: "
        if len(suspicious) == 0:
            print "No one :D"
        for item in suspicious:
            channel = item.user[10:]
            print "%s %s%d / %d = %0.3f   %s" %(channel, 
                                                " "*(20-len(channel)), #formatting spaces
                                                item.chatters, item.viewers, item.ratio,
                                                item.game
                                               )
            #print item.user[10:], "- %d / %d = %0.3f:" %(item.chatters, item.viewers, item.ratio,), "      ", item.game
        print
        print "We have confirmed: "
        if len(confirmed) == 0:
            print "No one :D"
        for item in confirmed:
            channel = item.user[10:]
            print "%s %s%d / %d = %0.3f   %s" %(channel, 
                                                " "*(20-len(channel)), #formatting spaces
                                                item.chatters, item.viewers, item.ratio,
                                                item.game
                                               )
            #print channel+": " + " "*20-len(channel) + \
            #        "%d / %d = %0.3f:" %(item.chatters, item.viewers, item.ratio,), item.game
        print
        print "Total of", len(suspicious)+len(confirmed), "botters"
        print
        print
Ejemplo n.º 5
0
def search_all_games():
    global global_sum
    try:
        topreq = requests.get("https://api.twitch.tv/kraken/games/top?limit=" +
                              str(num_games))
        while topreq.status_code != 200:
            print "trying to get top games..."
            topreq = requests.get(
                "https://api.twitch.tv/kraken/games/top?limit=" +
                str(num_games))
        topdata = topreq.json()
    except requests.exceptions.ConnectionError:
        print "connection error trying to get the game list. recursing :)))"
        return search_all_games
    except ValueError:
        print "nope. recursing. ~287 twitch_chatters.py"
        search_all_games()
    for i in range(0, len(topdata['top'])):
        game = removeNonAscii(topdata['top'][i]['game']['name'])
        print "__" + game + "__",
        print "(tweetmode off)" if not tweetmode else ""
        prev_suspicious = suspicious[:]  #make a duplicate of suspicious before things are added to the new suspicious list
        ratio = game_ratio(
            game
        )  #does remove elements from suspicious and puts them into confirmed
        for item in suspicious:
            if item.game == game and item in prev_suspicious:
                newconfirmed = [
                    i for i in confirmed
                    if i.game == game and item.user == i.user
                ]
                if newconfirmed != []:
                    suspicious.remove(item)
                    print item.user[
                        10:], "was found to have stopped botting", game + "!",
                    print " removing from suspicious list!"
                else:
                    suspicious.remove(item)
        print
        print "Average ratio for " + game + ": %0.3f" % ratio
        print
        print "Total global ratio: %0.3f" % (global_sum / float(global_cnt))
        print
        print "We are suspicious of: "
        if len(suspicious) == 0:
            print "No one :D"
        for item in suspicious:
            channel = item.user[10:]
            print "%s %s%d / %d = %0.3f   %s" % (
                channel,
                " " * (20 - len(channel)),  #formatting spaces
                item.chatters,
                item.viewers,
                item.ratio,
                item.game)
            #print item.user[10:], "- %d / %d = %0.3f:" %(item.chatters, item.viewers, item.ratio,), "      ", item.game
        print
        print "We have confirmed: "
        if len(confirmed) == 0:
            print "No one :D"
        for item in confirmed:
            channel = item.user[10:]
            print "%s %s%d / %d = %0.3f   %s" % (
                channel,
                " " * (20 - len(channel)),  #formatting spaces
                item.chatters,
                item.viewers,
                item.ratio,
                item.game)
            #print channel+": " + " "*20-len(channel) + \
            #        "%d / %d = %0.3f:" %(item.chatters, item.viewers, item.ratio,), item.game
        print
        print "Total of", len(suspicious) + len(confirmed), "botters"
        print
        print