def delete_negative_comment(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    comment_info = requests.get(request_url).json()
    if comment_info['meta']['code'] == 200:
        if len(comment_info['data']):
            #Here's a naive implementation of how to delete the negative comments
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    print 'Negative comment : %s' % (comment_text)
                    delete_url = (BASE_URL +
                                  'media/%s/comments/%s/?access_token=%s') % (
                                      media_id, comment_id, APP_ACCESS_TOKEN)
                    print 'DELETE request url : %s' % (delete_url)
                    delete_info = requests.delete(delete_url).json()
                    if delete_info['meta']['code'] == 200:
                        print 'Comment Successfully deleted!\n'
                    else:
                        print 'SORRY! Unable To Delete comment!'
                else:
                    print "Positive comment : %s\n" % (comment_text)
        else:
            print 'Already Have comments on the post!'
    else:
        print 'Status code other than 200 received!'


#delete_negative_comment(insta_username="******")
def delete_negative_comment(insta_username):
    media_id = get_post_id(insta_username)
    # takes input from the user for comment id to be deleted
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    comment_info = requests.get(request_url).json()

    if comment_info['meta']['code'] == 200:
        if len(comment_info['data']):
            #How to delete the negative comments
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    print 'Negative comment : %s' % (comment_text)
                    delete_url = (BASE_URL +
                                  'media/%s/comments/%s/?access_token=%s') % (
                                      media_id, comment_id, APP_ACCESS_TOKEN)
                    print 'DELETE request url : %s' % (delete_url)
                    delete_info = requests.delete(delete_url).json()

                    if delete_info['meta']['code'] == 200:
                        print 'Comment successfully deleted!\n'
                    else:
                        print 'Unable to delete comment!'
                else:
                    print 'Positive comment : %s\n' % (comment_text)
        else:
            print 'There are no existing comments on the post!'
    else:
        print 'Status code other than 200 received!'
Beispiel #3
0
def delete_negative_comment(insta_username):
    # Function Logic to Delete Negative Comments..
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s\n' % (request_url)
    comment_info = requests.get(request_url).json()

    if comment_info['meta']['code'] == 200:  #Check if the
        # re are Negative Comments Using textblob.sentiments Library
        if len(comment_info['data']):
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    print '\t(-)Negative comment : %s' % (comment_text)
                    delete_url = (BASE_URL +
                                  'media/%s/comments/%s/?access_token=%s') % (
                                      media_id, comment_id, APP_ACCESS_TOKEN)
                    print 'DELETE request url : %s' % (delete_url)
                    delete_info = requests.delete(delete_url).json()

                    if delete_info['meta'][
                            'code'] == 200:  #Check if negative comments are deleted or not
                        print '\t\t\t*****Comment successfully deleted!*****\n'
                    else:
                        print '\t\t\t*****Unable to delete comment!*****\n'
        else:
            print '\n\t\t\t*****There are no existing comments on the post!*****'
    else:  #if Page Not Found
        print '\n\t\t\t*****Status code other than 200 received!*****'
Beispiel #4
0
def like_a_post(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/likes') % (media_id)
    payload = {"access_token": APP_ACCESS_TOKEN}
    print 'POST request url : %s' % (request_url)
    post_a_like = requests.post(request_url, payload).json()
    if post_a_like['meta']['code'] == 200:
        print 'Like was successful!'
    else:
        print 'Your like was unsuccessful. Try again!'
def post_a_comment(insta_username):
    media_id = get_post_id(insta_username)
    comment_text = raw_input('your comment:')
    payload = {"access_token": APP_ACCESS_TOKEN, "text": comment_text}
    request_url = (BASE_URL + 'media/%s/comments') % (media_id)
    print 'POST request url : %s ' % (request_url)
    make_comment = requests.post(request_url, payload).json()
    if make_comment['meta']['code'] == 200:
        print "Post comment Successfully"
    else:
        print "Unable to add comment. try again!"
Beispiel #6
0
def like_a_post(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (base_url + 'media/%s/likes') % (media_id)
    payload = {"access_token": app_access_token}
    print 'POST request url : %s' % (request_url)
    post_a_like = requests.post(request_url, payload).json()

    if post_a_like['meta']['code'] == 200:
        print('Like was successful!')
    else:
        print('Your like was unsuccessful. Please try again!', )
Beispiel #7
0
def like_user_post(insta_username):
    # Function Logic to Like User's Recent Post

    media_id = get_post_id(insta_username)
    print(media_id)
    request_url = (BASE_URL + "media/"+media_id+"/likes")
    payload = {"access_token" : APP_ACCESS_TOKEN}
    post_a_like = requests.post(request_url,payload).json()
    if post_a_like['meta']['code'] == 200:
        print ('\n\t\t*****Like was successful!*****')
    else:
        print ('\n\t\t*****Your like was unsuccessful. Try again!*****')
Beispiel #8
0
def post_a_comment(insta_username):
    media_id = get_post_id(insta_username)
    comment_text = raw_input("Your comment: ")
    payload = {"access_token": app_access_token, "text": comment_text}
    request_url = (base_url + 'media/%s/comments') % (media_id)
    print 'POST request url : %s' % (request_url)
    make_comment = requests.post(request_url, payload).json()

    if make_comment['meta']['code'] == 200:
        print('Successfully added a new comment!')
    else:
        print('Unable to add comment. Please try again!')
Beispiel #9
0
def post_a_comment(insta_username):
    media_id=get_post_id(insta_username)
    comment_text=raw_input("Your Comment: ")
    payload={"access_token":APP_ACCESS_TOKEN, "text" : comment_text}
    request_url=(BASE_URL + 'media/%s/comments') % (media_id)
    print 'POST request url : %s ' % (request_url)
    make_comment=requests.post(request_url,payload).json()
    if make_comment['meta']['code'] ==200:
        print "sucessfully added a new comment"
    else:
        print "Sorry You Are Unable To add Comment. plz.. Try Again!"
#post_a_comment(insta_username="******")
Beispiel #10
0
def show_all_comment(insta_username):
    # Function Logic to Show all Comments..

    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print('GET request url : %s\n' % (request_url))
    comment_info = requests.get(request_url).json()

    if comment_info['meta'][
            'code'] == 200:  #Check if there are negative and positive comments..

        if len(comment_info['data']):
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    print('\t(-)Negative comment : %s' % (comment_text))
                else:
                    print('\t(+)Positive comment : %s' % (comment_text))
        else:
            print('\t*****There are no existing comments on the post!*****')

    #Plot the pie-Chart

        print(
            "\n\t*****Here is the Pie-Chart Analysis of Positive and Negative Comments.*****"
        )
        var1 = blob.sentiment.p_neg
        var2 = blob.sentiment.p_pos
        str_var1 = str(var1)
        str_var2 = str(var2)
        str_var1 = len(str_var1)
        str_var2 = len(str_var2)
        labels = 'Positive Comments', 'Negative Comments'
        sizes = [str_var1, str_var2]
        explode = (0, 0.1
                   )  # only "explode" the 2nd slice (i.e. 'Negative Comment')
        fig1, ax1 = plt.subplots()
        ax1.pie(sizes,
                explode=explode,
                labels=labels,
                autopct='%1.1f%%',
                shadow=True,
                startangle=90)
        ax1.axis('equal'
                 )  # Equal aspect ratio ensures that pie is drawn as a circle.
        plt.show()

    else:
        print('\n\t\t*****Status code other than 200 received!*****')
Beispiel #11
0
def like_a_post(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/likes') % (media_id)
    payload = {"access_token": APP_ACCESS_TOKEN}
    print 'POST request url: %s' % (request_url)
    post_a_like = requests.post(request_url, payload).json()
    if post_a_like['meta']['code'] == 200:
        print "like was successfull"
    else:
        print "Your like was unsuccessful.Plz Try Again........!"


#like_a_post(insta_username="******")
def like_list(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/likes?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url: %s' % (request_url)
    get_a_like = requests.get(request_url).json()
    if get_a_like['meta']['code'] == 200:
        print "Media with media id '{}' is liked by following users:".format(
            media_id)
        for (index, user_likes) in enumerate(get_a_like['data']):
            print "{}. {} ({}) - {}".format(index + 1, user_likes['full_name'],
                                            user_likes['id'],
                                            user_likes['username'])
    else:
        print "wrong input Plz Try Again........!"
Beispiel #13
0
def like_list(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/likes?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    get_like = requests.get(request_url).json()
    if get_like['meta']['code'] == 200:
        print "Media with media id %s is liked by following users;" % media_id
        if get_like['data'] > 0:
            for (index, user_likes) in enumerate(get_like['data']):
                print "%s,%s,%s,%s" % (index + 1, user_likes['full_name'],
                                       user_likes['id'],
                                       user_likes['username'])
    else:
        print "wrong input"
Beispiel #14
0
def fetch_like_list(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (base_url + 'media/%s/likes?access_token= %s') % (media_id,app_access_token )
    print 'GET request url : %s' % (request_url)
    list_of_likes_info = requests.get(request_url).json()

    if list_of_likes_info['meta']['code'] == 200:

        if len(list_of_likes_info['data']):
            for x in range(len(list_of_likes_info['data'])):
                print 'list of likes is %s' % (list_of_likes_info['data'][x]['username'])
        else:
            print ('likes does not exist.')

    else:
        print ('status code other than 200 received.')
Beispiel #15
0
def get_comment_list(insta_username):
    #fuction logic here
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    comment_info = requests.get(request_url).json()
    if comment_info['meta']['code'] == 200:
        for x in range(0, len(comment_info['data'])):
            comment_id = comment_info['data'][x]['id']
            comment_text = comment_info['data'][x]['text']
            blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
            if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                print 'Negative comment : %s' % (comment_text)
            else:
                print "Positive comment : %s\n" % (comment_text)
Beispiel #16
0
def list_of_comments(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    get_comment = requests.get(request_url).json()
    if get_comment['meta']['code'] == 200:
        print "Media with media id %s has comments from following users;" % media_id
        if get_comment['data'] > 0:
            for (index, user_comments) in enumerate(get_comment['data']):
                # print ("%s,%s,%s" % (index + 1, user_comments['id'], user_comments['username']))
                # print (user_comments)
                print("%d. %s is commented by %s") % (
                    index + 1, user_comments['text'],
                    user_comments['from']['full_name'])
    else:
        print "wrong input"
Beispiel #17
0
def post_comment(insta_username):
    post_id = get_post_id(insta_username)
    comment = raw_input("write the comment:>")
    payload = {'access_token': APP_ACCESS_TOKEN, 'text': comment}
    request_url = BASE_URL + 'media/%s/comments' % post_id
    print "POST request url %s" % request_url

    #send post request to the server and and store the response in a make_commect variable
    make_comment = requests.post(request_url, payload).json()

    #check what is the response from server
    if make_comment['meta']['code'] == 200:
        print "commect successfull posted "

    else:
        print "commect not posted"


#calling the defined function
Beispiel #18
0
def get_comments_list(insta_username):
    media_id = get_post_id(insta_username)
    if media_id is None:
        print("There is no media")
    else:
        request_url = base_url + "media/%s/comments/?access_token=%s" % (
            media_id, app_access_token)
        print "Get request url:%s" % request_url
        comment_list = requests.get(request_url).json()

    # check the status code, if comes 200 then show the list of comments
    if comment_list['meta']['code'] == 200:
        if len(comment_list['data']):
            print "The comments on the post :"
            for x in range(len(comment_list['data'])):
                comment_text = comment_list['data'][x]['text']
                print "comment: %s" % (comment_text)

        else:
            print("No comments on this post")
    else:
        print("Status code other than 200")
Beispiel #19
0
def delete_negative_comments(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (base_url + 'media/%s/comments/?access_token=%s') % (
        media_id, app_access_token)
    print 'GET request url : %s' % (request_url)
    comment_info = requests.get(request_url).json()

    if comment_info['meta']['code'] == 200:

        if len(comment_info['data']):

            for x in range(len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())

                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    print 'Negative comment : %s' % (comment_text)
                    delete_url = (base_url +
                                  'media/%s/comments/%s/?access_token=%s') % (
                                      media_id, comment_id, app_access_token)

                    print 'DELETE request url : %s' % (delete_url)
                    delete_info = requests.delete(delete_url).json()

                    if delete_info['meta']['code'] == 200:
                        print('Comment successfully deleted!\n')
                    else:
                        print('Unable to delete comment!')

                else:
                    print('Positive comment: %s\n') % (comment_info)

        else:
            print('There are no comments on this post.')

    else:
        print('Status code other than 200 received!')
def delete_negative_comment(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (
        media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s' % (request_url)
    comment_info = requests.get(request_url).json()
    no_neg_comm = 0
    no_pos_comm = 0
    if comment_info['meta']['code'] == 200:
        if len(comment_info['data']):
            #Here's a naive implementation of how to delete the negative comments :)
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                blob = TextBlob(comment_text, analyzer=NaiveBayesAnalyzer())
                if (blob.sentiment.p_neg > blob.sentiment.p_pos):
                    no_neg_comm += 1
                else:
                    no_pos_comm += 1
            plot_pie_chart(no_pos_comm, no_neg_comm)
        else:
            print 'There are no existing comments on the post!'
    else:
        print 'Status code other than 200 received!'