def remove_offline(): print "==REMOVING OFFLINE==" flag = False #flag is for styling the terminal, nothing else. to_remove = [] for item in suspicious: name = item.user originame = name[10:] #remove the http://www.twitch.tv/ if (user_ratio(originame) > 2*ratio_threshold or user_viewers(originame) < user_threshold/4): print originame + " appears to have stopped botting! removing from suspicious list" to_remove.append(item) else: print for item in to_remove: suspicious.remove(item) to_remove = [] for item in confirmed: if confirmed != []: flag = True #flag is for styling the terminal, nothing else. name = item.user originame = name[10:] #remove the http://www.twitch.tv/ if user_ratio(originame) > (2 * ratio_threshold) or user_viewers(originame) < 50: print originame + " appears to have stopped botting! removing from confirmed list" to_remove.append(item) else: print for item in to_remove: confirmed.remove(item) if flag: print print print "looping back around :D" print print
def remove_offline(): print "==REMOVING OFFLINE==" flag = False #flag is for styling the terminal, nothing else. to_remove = [] for item in suspicious: name = item.user originame = name[10:] #remove the http://www.twitch.tv/ if (user_ratio(originame) > 2 * ratio_threshold or user_viewers(originame) < user_threshold / 4): print originame + " appears to have stopped botting! removing from suspicious list" to_remove.append(item) else: print for item in to_remove: suspicious.remove(item) to_remove = [] for item in confirmed: if confirmed != []: flag = True #flag is for styling the terminal, nothing else. name = item.user originame = name[10:] #remove the http://www.twitch.tv/ if user_ratio(originame) > ( 2 * ratio_threshold) or user_viewers(originame) < 50: print originame + " appears to have stopped botting! removing from confirmed list" to_remove.append(item) else: print for item in to_remove: confirmed.remove(item) if flag: print print print "looping back around :D" print print
def user_ratio(user): """ :param user: string representing http://www.twitch.tv/<user> :return: the ratio of chatters to viewers in <user>'s channel """ chatters2 = 0 exceptions = get_exceptions() # Don't have to put ^ or $ at the beginning. Just use .* it's more concise. for regex in exceptions: if regex != '': if regex[0] != '^': regex = '^' + regex if regex[-1] != '$': regex += '$' if re.match(regex, user, re.I | re.S) != None: print user, "is alright :)", return 1 if user in get_frontpage_users(): print "nope,", user, "is a featured stream (being shown on the frontpage).", return 1 if is_being_hosted(user): print "nope,", user, "is being hosted by someone", return 1 if d2l_check: d2l_list = get_dota2lounge_list() if user in d2l_list: print user, "is being embedded in dota2lounge. nogo", return 1 chatters = user_chatters(user) if debug: chatters2 = get_chatters2(user) viewers = user_viewers(user) if viewers == -1: # This means something went wrong with the twitch servers, or internet cut out print "RECURSING BECAUSE OF 422 TWITCH ERROR" return user_ratio(user) if viewers and viewers != 0: # viewers == 0 => streamer offline maxchat = max(chatters, chatters2) ratio = float(maxchat) / viewers print user + ": " + str(maxchat) + " / " + str(viewers) + " = %0.3f" % ratio, if debug: print "(%d - %d)" % (chatters2, chatters), if chatters != 0: if debug: diff = abs(chatters2 - chatters) error = (100 * (float(diff) / chatters)) # Percent error else: return 0 if debug and error > 6: print " (%0.0f%% error)!" % error, if error < 99 and diff > 10: print "!!!!!!!!!!!!!!!!!!!" # If my chatters module goes wrong, i want to notice it. if ratio > 1: webbrowser.open("BDB - ratio for " + user + " = %0.3f" % ratio) print "????????????" else: print else: return 1 # User is offline. return ratio
def user_ratio(user): global debug time.sleep(5) print "checking", user, "ratio" chatters2 = 0 if user in get_frontpage_users(): print "nope,", user, "is on the front page of twitch." return 1 exceptions = get_exceptions() # users don't have to put ^ or $ at the beginning. just use .* it's more readable. for regex in exceptions: if regex != "": if regex[0] != "^": regex = "^" + regex if regex[-1] != "$": regex += "$" # if the username matches the regex if re.match(regex, user, re.I | re.S) != None: print user, "is alright :)", return 1 if d2l_check: d2l_list = get_dota2lounge_list() if user in d2l_list: print user, "is being embedded in dota2lounge. nogo" return 1 print "here1" chatters = user_chatters(user) if debug: chatters2 = get_chatters2(user) print "here2" viewers = user_viewers(user) print "here3" if viewers and viewers != 0 and viewers != None: maxchat = max(chatters, chatters2) ratio = float(maxchat) / viewers print user + ": " + str(maxchat) + " / " + str(viewers) + " = %0.3f" % ratio, if debug: print "(%d - %d)" % (chatters2, chatters), if chatters != 0: if debug: diff = abs(chatters2 - chatters) error = 100 * (float(diff) / chatters) # percent error else: return 0 if debug and error > 6: print " (%0.0f%% error)!" % error, if error < 99 and diff > 10: print "!!!!!!!!!!!!!!!!!!!" # if my chatters module goes wrong, i want to notice it. if ratio > 1: webbrowser.open("BDB - ratio for " + user + " = %0.3f" % (ratio)) print "????????????" else: print else: print else: return 1 # user is offline return ratio
def user_ratio(user): chatters2 = 0 exceptions = get_exceptions() #users don't have to put ^ or $ at the beginning. just use .* it's more readable. for regex in exceptions: if regex != '': if regex[0] != '^': regex = '^' + regex if regex[-1] != '$': regex += '$' #if the username matches the regex if re.match(regex, user, re.I | re.S) != None: print user, "is alright :)", return 1 if user in get_frontpage_users(): print "nope,", user, "is on the front page of twitch.", return 1 if d2l_check: d2l_list = get_dota2lounge_list() if user in d2l_list: print user, "is being embedded in dota2lounge. nogo", return 1 chatters = user_chatters(user) if debug: chatters2 = get_chatters2(user) viewers = user_viewers(user) if viewers == -1: #this means something went wrong with the twitch servers, or user's internet died print "RECURSING BECAUSE OF 422 TWITCH ERROR" return user_ratio(user) if viewers and viewers != 0: #viewers == 0 => streamer offline maxchat = max(chatters, chatters2) ratio = float(maxchat) / viewers print user + ": " + str(maxchat) + " / " + str( viewers) + " = %0.3f" % ratio, if debug: print "(%d - %d)" % (chatters2, chatters), if chatters != 0: if debug: diff = abs(chatters2 - chatters) error = (100 * (float(diff) / chatters)) #percent error else: return 0 if debug and error > 6: print " (%0.0f%% error)!" % error, if error < 99 and diff > 10: print "!!!!!!!!!!!!!!!!!!!" #if my chatters module goes wrong, i want to notice it. if ratio > 1: webbrowser.open("BDB - ratio for " + user + " = %0.3f" % (ratio)) print "????????????" else: print else: return 1 # user is offline return ratio
def user_ratio(user): chatters2 = 0 exceptions = get_exceptions() #users don't have to put ^ or $ at the beginning. just use .* it's more readable. for regex in exceptions: if regex != '': if regex[0] != '^': regex = '^' + regex if regex[-1] != '$': regex += '$' #if the username matches the regex if re.match(regex, user, re.I|re.S) != None: print user, "is alright :)", return 1 if user in get_frontpage_users(): print "nope,", user, "is on the front page of twitch.", return 1 if d2l_check: d2l_list = get_dota2lounge_list() if user in d2l_list: print user, "is being embedded in dota2lounge. nogo", return 1 chatters = user_chatters(user) if debug: chatters2 = get_chatters2(user) viewers = user_viewers(user) if viewers == -1: #this means something went wrong with the twitch servers, or user's internet died print "RECURSING BECAUSE OF 422 TWITCH ERROR" return user_ratio(user) if viewers and viewers != 0: #viewers == 0 => streamer offline maxchat = max(chatters, chatters2) ratio = float(maxchat) / viewers print user + ": " + str(maxchat) + " / " + str(viewers) + " = %0.3f" %ratio, if debug: print "(%d - %d)" %(chatters2, chatters), if chatters != 0: if debug: diff = abs(chatters2 - chatters) error = (100 * (float(diff) / chatters)) #percent error else: return 0 if debug and error > 6: print " (%0.0f%% error)!" %error, if error < 99 and diff > 10: print "!!!!!!!!!!!!!!!!!!!" #if my chatters module goes wrong, i want to notice it. if ratio > 1: webbrowser.open("BDB - ratio for "+user+" = %0.3f" %(ratio)) print "????????????" else: print else: return 1 # user is offline return ratio
def user_ratio(user): chatters = user_chatters(user) if chatters == None: return 1 #some error occurred. streamer offline? twitch down? viewers = user_viewers(user) if viewers and viewers != 0: ratio = float(chatters) / viewers if chatters == 0: return 0 else: return 1 # user is offline return ratio
def destroy_offline(): stati = api.GetUserTimeline(twitter_name, count=200) if len(stati) == 1: if stati[0].text == sentinel_msg: return for status in stati: name = status.text.split(" ")[0] if user_ratio(name) > (0.17) or user_viewers(name) < 200: print name + " appears to have stopped botting! deleting tweet." try: api.DestroyStatus(status.id) except twitter.TwitterError: time.sleep(5) pass if len(api.GetUserTimeline(twitter_name, count=200)) == 0: send_sentinel_tweet()