I recently bought a raspberry pi for many projects, one of which is reddit bots. I'm using PRAW to make the bot and it works perfectly on my desktop PC(Windows 8.1) but on my raspberry by (Raspbian) it doesn't seem to work. I've narrowed it down to these few lines in question.
Brief explanation of what I'm trying to do: Get the selftext of the post and split it by spaces into words then check if certain words are in the post.
text = submission.selftext.replace(","," ").encode("utf-8").lower().split()
for i in range (0, len(players)):
player = players[i].lower()
if player in text:
print(player)
On my PC this works fine but on the Pi the if statement was never triggered even though I'm using the EXACT SAME POST for each of these tests.
If you are not familiar with PRAW, I'm splitting a string and looking for words inside it, where text
is the array of words to look through and players
is the dictionary.
Edit: The code does not produce any errors, it just doesn't trigger the if statement like it does on my desktop.
Edit #2: Seems that it works fine with hard-coded variable text
and player
. I left text hard-coded to include an entry from what should be in players
but it would not find it which leads me to believe the error is in how I create the list players
Below is the method that I use to create it.
def getPlayers():
players = []
with open("PlayerIDs.txt") as f:
for line in f:
players.append(line)
return players
SOLUTION between Python 2 and 3 there were changes to how unicode and encoding in general worked and therefor the code would not run on python 2.x on my pi. I ended up installing python3 and using virtualenv to setup python 3 and it all works fine now :)