1

I'm using two files for this project. Snapchat.py and test.py

Snapchat.py contains the following (showing the important part):

def add_friend(self, username):
    """Add user as friend
    Returns JSON response.
    Expected messages:
        Success: '{username} is now your friend!'
        Pending: '{username} is private. Friend request sent.'
        Failure: 'Sorry! Couldn't find {username}'
    :param username: Username to add as a friend
    """
    r = self._request('friend', {
        'action': 'add',
        'friend': username,
        'username': self.username
    })
    return r.json()

The file test.py, that I am currently working on has the following code:

#including Snapchat in test.py
from snapchat import Snapchat

s = Snapchat()

username = raw_input('Enter your username: ')
password = raw_input('Enter your password: ')
friend = raw_input('Enter friend name: ')
s.login(username, password)

s.add_friend(friend)

The important part here is:

    Returns JSON response.
    Expected messages:
        Success: '{username} is now your friend!'
        Pending: '{username} is private. Friend request sent.'
        Failure: 'Sorry! Couldn't find {username}'

I want that response printed at the end of the test.py file in the command shell.

Though I have no clue on how to do this, I have tried importing it in the test.py file and printing it, but not working.

1
  • I don't see any reference to the R language here, so I'm removing the [r] tag Commented Nov 17, 2014 at 6:11

1 Answer 1

1

Please note that the Messages you pasted in your question will infact be returned by the add_friend method, so you don't need to do anything.

Simply print them like;

#First you need to see what is the response for your login call
login_response = s.login(username, password)
print str(login_response)

#if you wish to access some value in this response
value = login_response.get("the_value", {the default value})

if value: #incase you want to make sure you logged in correctly   
    json_response = s.add_friend(friend)
    print str(json_response)
Sign up to request clarification or add additional context in comments.

12 Comments

Thanks! I have tried it, but it still does not give me response.
It is sort of a pseudo code. You need to comeup with proper implementation to return the status code and the json response. I don't know the library you are using for making http requests.
where can I see that?
What is this "self._request"? which library is it using to make http calls? check it...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.