Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't run the follower compare on every twitch message. #9

Open
kbigliar opened this issue Jan 10, 2019 · 0 comments
Open

Don't run the follower compare on every twitch message. #9

kbigliar opened this issue Jan 10, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@kbigliar
Copy link
Contributor

TwitchBot/bot.py

Lines 497 to 574 in 2a86f6d

# Get new follower list and format it to compare with unfollowers
followers()
test = []
for i in range(len(followerList)):
test.insert(0, followerList[i]['from_name'].encode('ascii', 'ignore'))
test = map(str.strip, test)
# Get existing follower list
if not os.path.exists('followerData.csv'):
open('followerData.csv', "w+").close()
csvfile = open('followerData.csv', "rb")
followerDataReader = csv.reader(csvfile, delimiter=",")
followerLines = list(followerDataReader)
csvfile.close()
# Compare follower lists
newFollowers = [item for item in test if item not in [i[0] for i in followerLines[1:]]]
unfollowers = [item for item in [i[0] for i in followerLines[1:]] if item not in test]
# thank new follower and add to existing list
if len(newFollowers) > 0:
if len(followerLines) == 0:
followerLines.append(
["Username", "FollowLength", "IsFollower", "BatName", "BatGender", "BatColor",
"IsSubscriber"])
followerLines.append(
[Channel[1:], "0", "1", "", "", "", ""])
for i in range(len(newFollowers)):
followerLines.append([newFollowers[i], "", "", "", "", "", ""])
csvfile = open('followerDataNew.csv', "wb")
followerDataWriter = csv.writer(csvfile, delimiter=",")
followerDataWriter.writerows(followerLines)
csvfile.close()
os.remove('followerData.csv')
os.rename('followerDataNew.csv', 'followerData.csv')
if len(newFollowers) == 1:
message("Thank you for following the channel " + " ".join(
newFollowers) + "! Type !bat to see your the information on your :bat:")
if len(newFollowers) > 1:
message("Thank you for following the channel " + ", ".join(newFollowers[0:-1]) + " and " +
newFollowers[-1] + "! Type !bat to see the information on your :bat:")
# If someone is a follower set isFollower to 1
for i1 in range(len(followerList)):
for i2 in range(len(followerLines)):
if followerList[i1]['from_name'].encode('ascii', 'ignore').lower().rstrip() == \
followerLines[i2][0].lower().rstrip():
followerLines[i2][2] = "1"
# If someone unfollows set isFollower to 0
for i1 in range(len(unfollowers)):
for i2 in range(len(followerLines)):
if not followerLines[i2][0].lower().rstrip() == Channel[1:].lower().rstrip():
if followerLines[i2][0] == unfollowers[i1]:
followerLines[i2][2] = "0"
# Assign gender
for i in range(len(followerLines)):
if followerLines[i][4] == "":
maleFemale = random.randint(0, 1)
if maleFemale == 1:
followerLines[i][4] = 'female'
else:
followerLines[i][4] = 'male'
# Assign Name
for i in range(len(followerLines)):
try:
if followerLines[i][3] == "":
if followerLines[i][4].lower() == 'male':
randomNumber = random.randint(0, len(batMaleNames))
maleName = batMaleNames[randomNumber]
followerLines[i][3] = maleName
if followerLines[i][4].lower() == 'female':
randomNumber = random.randint(0, len(batFemaleNames))
femaleName = batFemaleNames[randomNumber]
followerLines[i][3] = femaleName
except IndexError:
print 'Skipped adding gender. Will add next time this loops'
pass

You can call it about every 10 seconds in your while TRUE loop if you want instead of on every message (seen in #8 ) to constantly cycle the list without tying into chat messages.

@kbigliar kbigliar changed the title Give this it's own function. Don't run the follower compare on every twitch message. Jan 10, 2019
@Ridgure Ridgure added the enhancement New feature or request label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants