Open jcherrera opened 9 years ago
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:
``` python
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.
I tried: from argparse import ArgumentParser from snapchat_bots import SnapchatBot
class StorifierBot(SnapchatBot): def on_snap(self, sender, snap): self.post_story(snap)
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")
But I am not able to make it add friends by itself.