agermanidis / SnapchatBot

[deprecated] Python library for building bots that live on Snapchat
MIT License
517 stars 105 forks source link

Won't add friend #55

Open jcherrera opened 9 years ago

jcherrera commented 9 years ago

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.

jcherrera commented 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?

N07070 commented 9 years ago

Yes; please look for the try... except... statement in the python docs, you'll learn much ! :smile:

jcherrera commented 9 years ago

@N07070 Where can I find that?

krissrex commented 9 years ago

@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.