SnapchatBot
SnapchatBot copied to clipboard
Won't add friend
I tried: from argparse import ArgumentParser from snapchat_bots import SnapchatBot
class StorifierBot(SnapchatBot): def on_snap(self, sender, snap): self.post_story(snap)
def on_friend_add(self, friend):
self.add_friend(friend) #I also tried with seld.add_friend(self,friend) with no luck
def on_friend_delete(self, friend):
self.delete_friend(friend) #I also tried with seld.delete_friend(self,friend) with no luck
if name == 'main': parser = ArgumentParser("Storifier Bot") parser.add_argument('-u', '--username', required=True, type=str, help="Username of the account to run the bot on") parser.add_argument('-p', '--password', required=True, type=str, help="Password of the account to run the bot on")
args = parser.parse_args()
bot = StorifierBot(args.username, args.password)
bot.listen()
But I am not able to make it add friends by itself.
When I run this the bot is able to add all snaps to its story, though it does not add/delete new friends...
Also, how can the bot be persistent, meaning that if it fails it would run again?
Yes; please look for the try... except... statement in the python docs, you'll learn much ! :smile:
@N07070 Where can I find that?
@jcherrera Your code is a bit tricky to understand when you dont use code blocks. Identation is gone, and I cant tell if you are writing code or talking about it. Please put code inside a block like this:
```python
code
```
As for persistence, N07070s suggestion would turn out like this:
if __name__ == '__main__':
# code to set up would go here
while True:
try:
bot.listen()
except Exception:
print "Exception happened"
Note that using except Exception
will catch all exceptions, even ctrl c, so you might want to select what exceptions to catch more precisely.
Have a look at Errors and Exceptions part 8.3 Handling Exceptions.