Search Engine's AutoSuggestions impact of Movie Piracy

Final Project for JOUR 479/779 Understanding search enginee autosuggestions impact on Movie Piracy


In [256]:
import requests
import urllib
import warnings
import pandas as pd
import datetime
import os,glob
import csv
import io
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

warnings.filterwarnings('ignore')

#Constant
def MY_FILE():
    return "Data/Sunday-01-Box-Office/"

In [257]:
if not os.path.exists(MY_FILE()):
    os.makedirs(MY_FILE())
    
for filename in glob.glob(MY_FILE()+"OP_*"):
    os.remove(filename)

In [258]:
# ----------------------------------------------------------------------------------------------------------------
# collect_autosuggestions
#
# parameters:
# "source" is either "google" or "bing"
# "tld" stands for "top level domain" and can be any of the 2-letter country codes listed 
#  here where google operates: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
# "lang" is the language of the suggestions returned, should be two letter codes 
# from here: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
# "query" is the query that you would like to see autocompleted
# ----------------------------------------------------------------------------------------------------------------

def collect_autosuggestions(source, tld, lang, query):
    if source == "google":
        # Some info on this api: http://shreyaschand.com/blog/2013/01/03/google-autocomplete-api/
        url = 'http://www.google.'+tld+'/complete/search?&client=firefox&%s' % (urllib.parse.urlencode(
                {'q': query.encode('utf-8'), 'hl': lang}))
       
    elif source == "bing":
        # Note: for Bing the language is controlled by the tld, so the lang parameter will have no effect on its own
        url = 'http://api.bing.com/osjson.aspx?%s' % (urllib.parse.urlencode(
                {'query': query.encode('utf-8'), 'cc': tld}))
   
    r = requests.get(url)
    suggestions = r.json()[1]
    return suggestions

In [259]:
movies_List = pd.read_csv("Data/BoxOffice.csv",encoding = "ISO-8859-1",low_memory=False,
                          names=["Ranking", 'Last Week Ranking','Movie Title','Movie Rating'])
movies_List


Out[259]:
index Ranking Last Week Ranking Movie Title Movie Rating
0 1 NaN The Jungle Book $42,439,000 4,041
1 2 NaN The Huntsman: Winter's War $9,390,000 3,802
2 3 NaN Keanu $9,350,000 2,658
3 4 NaN Mother's Day $8,302,319 3,035
4 5 NaN Barbershop: The Next Cut $6,125,000 2,310
5 6 NaN Zootopia $5,006,000 2,487
6 7 NaN Ratchet & Clank $4,823,000 2,891
7 8 NaN The Boss $4,250,000 2,823
8 9 NaN Batman v Superman: Dawn of Justice $3,810,000 2,330
9 10 NaN Criminal (2016) $1,325,000 1,578
10 NaN NaN My Big Fat Greek Wedding 2 $1,080,000 1,092
11 NaN NaN Green Room $960,000 470
12 NaN NaN A Hologram for the King $931,600 523
13 NaN NaN Eye in the Sky $863,377 614
14 NaN NaN Compadres $650,000 368
15 NaN NaN Miracles from Heaven $525,000 660
16 NaN NaN Papa: Hemingway in Cuba $491,200 325
17 NaN NaN Hello, My Name is Doris $456,870 404
18 NaN NaN Deadpool $440,000 409
19 NaN NaN Everybody Wants Some!! $360,000 442
20 NaN NaN Miles Ahead $341,780 390
21 NaN NaN Sing Street $330,000 104
22 NaN NaN The Divergent Series: Allegiant $295,000 410
23 NaN NaN 10 Cloverfield Lane $290,000 305
24 NaN NaN Kung Fu Panda 3 $284,000 258
25 NaN NaN Elvis & Nixon $198,696 310
26 NaN NaN The Meddler $174,369 24
27 NaN NaN The Man Who Knew Infinity $88,134 6
28 NaN NaN Spotlight $88,128 224
29 NaN NaN Hardcore Henry $60,000 119

The Top Priated Movie According to Torrent Freak


In [260]:
def collect_complete_Suggestions(search_term):
    #print ("Analysing Search Enginee Suggestion for {}".format(search_term))
    
    suggestions_google = collect_autosuggestions("google", "com", "en", search_term)    
    suggestions_bing = collect_autosuggestions("bing", "com", "en", search_term)    

    suggestions_google_df = pd.DataFrame({"suggestion": suggestions_google})
    suggestions_google_df["Movie Name"] = search_term
    suggestions_google_df["Search Enginee"] = "Google"
    suggestions_google_df["datetime"] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
    suggestions_google_df["Order Number"]=suggestions_google_df.index+1
    
    suggestions_bing_df = pd.DataFrame({"suggestion": suggestions_bing})
    suggestions_bing_df["Movie Name"] = search_term
    suggestions_bing_df["Search Enginee"] = "Bing"
    suggestions_bing_df["datetime"] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
    suggestions_bing_df["Order Number"]=suggestions_bing_df.index+1

    suggestions_bing_df = suggestions_bing_df[suggestions_bing_df.index < 10]

    suggestions_df = suggestions_google_df.append(suggestions_bing_df, ignore_index=True)
    
    suggestions_df = suggestions_df[["Order Number",'Search Enginee',"Movie Name","suggestion","datetime"]]
    suggestions_df.to_csv(MY_FILE()+'OP_Movie_Search_Suggestions.csv',mode = 'a',header=False,index=False)
    
    #print ("====================Analysis Completed=============================")
#End of Function

In [261]:
def collect_detail_Suggestions(movie_name):
    
    #print ("Analysing Detailed Search Enginee Suggestion for {}".format(movie_name))
     #Writing Headers
    file_name = MY_FILE()+'OP_'+movie_name+'.csv'
    with open(file_name, 'w+', newline='') as fp:
        a = csv.writer(fp, delimiter=',')
        data = [["Order Number",'Search Enginee', "Movie Name","Sub Term","Suggestion","Date & Time",'Character Typed']]
        a.writerows(data)
    
    for i, character in enumerate(movie_name):
        if i > 3:
            title_Name=movie_name
            title = title_Name[0:i]
            suggestions_google = collect_autosuggestions("google", "com", "en", title)    
            suggestions_bing = collect_autosuggestions("bing", "com", "en", title)    

            suggestions_google_df = pd.DataFrame({"suggestion": suggestions_google})
            suggestions_google_df["Movie Name"] = movie_name
            suggestions_google_df["Sub Term"] = title
            suggestions_google_df["Search Enginee"] = "Google"
            suggestions_google_df["datetime"] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
            suggestions_google_df["Order Number"]=suggestions_google_df.index+1
            suggestions_google_df["Character_Typed"]=i

            
            suggestions_bing_df = pd.DataFrame({"suggestion": suggestions_bing})
            suggestions_bing_df["Movie Name"] = movie_name
            suggestions_bing_df["Sub Term"] = title
            suggestions_bing_df["Search Enginee"] = "Bing"
            suggestions_bing_df["datetime"] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
            suggestions_bing_df["Order Number"]=suggestions_bing_df.index+1
            suggestions_bing_df["Character_Typed"]=i


            suggestions_bing_df = suggestions_bing_df[suggestions_bing_df.index < 10]
            
            suggestions_df = suggestions_google_df.append(suggestions_bing_df, ignore_index=True) 
            suggestions_df = suggestions_df[["Order Number",'Search Enginee', "Movie Name","Sub Term","suggestion","datetime"
                                            ,'Character_Typed']]
            suggestions_df.to_csv(file_name,mode = 'a',header=False,index=False)            
    #print ("=================================================")   
#End of Function

In [262]:
def perform_detailed_analysis(movie_name):
    detailed_List = pd.read_csv(MY_FILE()+'OP_'+movie_name+'.csv')
    summary_list = detailed_List.groupby(['Search Enginee', 'Suggestion']).size().reset_index(name='occurrence')
    summary_list = summary_list.sort_index(by=['occurrence'], ascending=[False])
    
    with open(MY_FILE()+'OP_'+movie_name+'_Summary.csv', 'w+', newline='') as fp:
        a = csv.writer(fp, delimiter=',')
        data = [["Search Enginee",'Suggestion',"Occurrence"]]
        a.writerows(data)
    summary_list.to_csv(MY_FILE()+'OP_'+movie_name+'_Summary.csv',mode = 'a',header=False,index=False)  
#End of Function

In [263]:
def filter_piracy_terms(movie_name):
    detail_movie_data = pd.read_csv(MY_FILE()+'OP_'+movie_name+'.csv')
    piracy_tag = "online|full movie|torrent|putlocker|free"
    filtered_List = detail_movie_data[detail_movie_data['Suggestion'].str.contains(piracy_tag)==True]
    filtered_List = filtered_List.sort_index(by=['Character Typed'], ascending=[True])
    
    with open(MY_FILE()+'OP_'+movie_name+'_Filtered.csv', 'w+', newline='') as fp:
        a = csv.writer(fp, delimiter=',')
        data = [["Order Number",'Search Enginee', "Movie Name","Sub Term","Suggestion","Date & Time",'Character Typed']]
        a.writerows(data)
        
    filtered_List.to_csv(MY_FILE()+'OP_'+movie_name+'_Filtered.csv',mode = 'a',header=False,index=False)
    
    summary_movie_data = pd.read_csv(MY_FILE()+'OP_'+movie_name+'_Summary.csv')
    Summary_filtered_List = summary_movie_data[summary_movie_data['Suggestion'].str.contains(piracy_tag)==True] 
    
    with open(MY_FILE()+'OP_'+movie_name+'_Summary_Filtered.csv', 'w+', newline='') as fp:
        a = csv.writer(fp, delimiter=',')
        data = [["Search Enginee",'Suggestion',"Occurrence"]]
        a.writerows(data)
    
    Summary_filtered_List.to_csv(MY_FILE()+'OP_'+movie_name+'_Summary_Filtered.csv',mode = 'a',header=False,index=False)  
#End of Function

In [264]:
#Looping through each movies to anaylse search enginee suggestions
#Writing Headers
with open(MY_FILE()+'OP_Movie_Search_Suggestions.csv', 'w+', newline='') as fp:
    a = csv.writer(fp, delimiter=',')
    data = [["Order Number",'Search Enginee',"Movie Name","Suggestion","Date & Time"]]
    a.writerows(data)
    
for index, row in movies_List.iterrows():
    print ("Analysis For {} ".format(row['Movie Title']))
    collect_complete_Suggestions(row['Movie Title'])
    collect_detail_Suggestions(row['Movie Title'])
    perform_detailed_analysis(row['Movie Title'])
    filter_piracy_terms(row['Movie Title'])
    print ("Analysis Completed")


Analysis For $42,439,000 
Analysis Completed
Analysis For $9,390,000 
Analysis Completed
Analysis For $9,350,000 
Analysis Completed
Analysis For $8,302,319 
Analysis Completed
Analysis For $6,125,000 
Analysis Completed
Analysis For $5,006,000 
Analysis Completed
Analysis For $4,823,000 
Analysis Completed
Analysis For $4,250,000 
Analysis Completed
Analysis For $3,810,000 
Analysis Completed
Analysis For $1,325,000 
Analysis Completed
Analysis For $1,080,000 
Analysis Completed
Analysis For $960,000 
Analysis Completed
Analysis For $931,600 
Analysis Completed
Analysis For $863,377 
Analysis Completed
Analysis For $650,000 
Analysis Completed
Analysis For $525,000 
Analysis Completed
Analysis For $491,200 
Analysis Completed
Analysis For $456,870 
Analysis Completed
Analysis For $440,000 
Analysis Completed
Analysis For $360,000 
Analysis Completed
Analysis For $341,780 
Analysis Completed
Analysis For $330,000 
Analysis Completed
Analysis For $295,000 
Analysis Completed
Analysis For $290,000 
Analysis Completed
Analysis For $284,000 
Analysis Completed
Analysis For $198,696 
Analysis Completed
Analysis For $174,369 
Analysis Completed
Analysis For $88,134 
Analysis Completed
Analysis For $88,128 
Analysis Completed
Analysis For $60,000 
Analysis Completed

In [265]:
first_occurrence = pd.DataFrame()
least_order = pd.DataFrame()

for index, row in movies_List.iterrows():
    Movie_Name = row['Movie Title']
    filtered_data = pd.read_csv(MY_FILE()+'OP_'+Movie_Name+'_Filtered.csv')
    
    first_row = filtered_data.head(1)
    first_occurrence = first_occurrence.append(first_row, ignore_index=True) 
    
    filtered_data = filtered_data.sort_index(by=['Order Number'], ascending=[True])
    first_row = filtered_data.head(1)
    #least_order = least_order.append(first_row[["Movie Name","Order Number"]], ignore_index=True) 
    
    filtered_summary_data = pd.read_csv(MY_FILE()+'OP_'+Movie_Name+'_Summary_Filtered.csv')
    filtered_summary_data = filtered_summary_data.groupby(by=['Search Enginee'])['Occurrence'].sum().reset_index(name='Total')
    if filtered_summary_data.empty:        
        print ("No Data for the movie:{} ".format(Movie_Name))  
        first_row.loc[len(first_row)]=['0','0',Movie_Name,'0','0','0','0']
        first_row["Total Bing Suggestion"] = 0
        first_row["Total Google Suggestion"] = 0
        least_order = least_order.append(first_row[["Movie Name","Character Typed","Order Number","Total Bing Suggestion"
                                                    ,"Total Google Suggestion"]], ignore_index=True) 
        first_occurrence = first_occurrence.append(first_row, ignore_index=True) 
        print (least_order)
    else:        
        if(len(filtered_summary_data.index)==2):
            if filtered_summary_data.iloc[0]['Search Enginee'] == 'Bing':
                first_row["Total Bing Suggestion"] = filtered_summary_data.iloc[0]['Total']
                first_row["Total Google Suggestion"] = filtered_summary_data.iloc[1]["Total"]
            else:
                first_row["Total Bing Suggestion"] = filtered_summary_data.iloc[1]['Total']
                first_row["Total Google Suggestion"] = filtered_summary_data.iloc[0]["Total"]
        else:
            if filtered_summary_data.iloc[0]['Search Enginee'] == 'Bing':
                first_row["Total Bing Suggestion"] = filtered_summary_data.iloc[0]['Total']
                first_row["Total Google Suggestion"] = 0
            else:
                first_row["Total Bing Suggestion"] = 0
                first_row["Total Google Suggestion"] = filtered_summary_data.iloc[0]["Total"]

        least_order = least_order.append(first_row[["Movie Name","Character Typed","Order Number","Total Bing Suggestion"
                                                    ,"Total Google Suggestion"]], ignore_index=True) 
    
first_occurrence = first_occurrence[["Movie Name","Character Typed","Order Number"]]
Final_dataframe = first_occurrence.merge(least_order,on='Movie Name')
Final_dataframe["Total Suggestions"] = Final_dataframe["Total Bing Suggestion"] + Final_dataframe["Total Google Suggestion"]
Final_dataframe[["Movie Name","Character Typed_x","Order Number_x","Order Number_y","Character Typed_y",
                "Total Bing Suggestion","Total Google Suggestion","Total Suggestions"]]


No Data for the movie:$9,390,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
No Data for the movie:$9,350,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
No Data for the movie:$8,302,319 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
No Data for the movie:$6,125,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   
4   $6,125,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
4                        0  
No Data for the movie:$4,823,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   
4   $6,125,000               0            0                      0   
5   $5,006,000               5            8                      1   
6   $4,823,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
4                        0  
5                        0  
6                        0  
No Data for the movie:$4,250,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   
4   $6,125,000               0            0                      0   
5   $5,006,000               5            8                      1   
6   $4,823,000               0            0                      0   
7   $4,250,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
4                        0  
5                        0  
6                        0  
7                        0  
No Data for the movie:$3,810,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   
4   $6,125,000               0            0                      0   
5   $5,006,000               5            8                      1   
6   $4,823,000               0            0                      0   
7   $4,250,000               0            0                      0   
8   $3,810,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
4                        0  
5                        0  
6                        0  
7                        0  
8                        0  
No Data for the movie:$1,325,000 
    Movie Name Character Typed Order Number  Total Bing Suggestion  \
0  $42,439,000               5            3                      0   
1   $9,390,000               0            0                      0   
2   $9,350,000               0            0                      0   
3   $8,302,319               0            0                      0   
4   $6,125,000               0            0                      0   
5   $5,006,000               5            8                      1   
6   $4,823,000               0            0                      0   
7   $4,250,000               0            0                      0   
8   $3,810,000               0            0                      0   
9   $1,325,000               0            0                      0   

   Total Google Suggestion  
0                        1  
1                        0  
2                        0  
3                        0  
4                        0  
5                        0  
6                        0  
7                        0  
8                        0  
9                        0  
No Data for the movie:$960,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
No Data for the movie:$931,600 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
No Data for the movie:$863,377 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
No Data for the movie:$650,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
No Data for the movie:$525,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
No Data for the movie:$491,200 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
No Data for the movie:$456,870 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
No Data for the movie:$440,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
No Data for the movie:$341,780 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
No Data for the movie:$330,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
No Data for the movie:$295,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
No Data for the movie:$290,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
No Data for the movie:$284,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
No Data for the movie:$198,696 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   
25     $198,696               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
25                        0  
No Data for the movie:$174,369 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   
25     $198,696               0            0                      0   
26     $174,369               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
25                        0  
26                        0  
No Data for the movie:$88,134 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   
25     $198,696               0            0                      0   
26     $174,369               0            0                      0   
27      $88,134               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
25                        0  
26                        0  
27                        0  
No Data for the movie:$88,128 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   
25     $198,696               0            0                      0   
26     $174,369               0            0                      0   
27      $88,134               0            0                      0   
28      $88,128               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
25                        0  
26                        0  
27                        0  
28                        0  
No Data for the movie:$60,000 
     Movie Name Character Typed Order Number  Total Bing Suggestion  \
0   $42,439,000               5            3                      0   
1    $9,390,000               0            0                      0   
2    $9,350,000               0            0                      0   
3    $8,302,319               0            0                      0   
4    $6,125,000               0            0                      0   
5    $5,006,000               5            8                      1   
6    $4,823,000               0            0                      0   
7    $4,250,000               0            0                      0   
8    $3,810,000               0            0                      0   
9    $1,325,000               0            0                      0   
10   $1,080,000               4           10                      1   
11     $960,000               0            0                      0   
12     $931,600               0            0                      0   
13     $863,377               0            0                      0   
14     $650,000               0            0                      0   
15     $525,000               0            0                      0   
16     $491,200               0            0                      0   
17     $456,870               0            0                      0   
18     $440,000               0            0                      0   
19     $360,000               5            8                      1   
20     $341,780               0            0                      0   
21     $330,000               0            0                      0   
22     $295,000               0            0                      0   
23     $290,000               0            0                      0   
24     $284,000               0            0                      0   
25     $198,696               0            0                      0   
26     $174,369               0            0                      0   
27      $88,134               0            0                      0   
28      $88,128               0            0                      0   
29      $60,000               0            0                      0   

    Total Google Suggestion  
0                         1  
1                         0  
2                         0  
3                         0  
4                         0  
5                         0  
6                         0  
7                         0  
8                         0  
9                         0  
10                        0  
11                        0  
12                        0  
13                        0  
14                        0  
15                        0  
16                        0  
17                        0  
18                        0  
19                        0  
20                        0  
21                        0  
22                        0  
23                        0  
24                        0  
25                        0  
26                        0  
27                        0  
28                        0  
29                        0  
Out[265]:
Movie Name Character Typed_x Order Number_x Order Number_y Character Typed_y Total Bing Suggestion Total Google Suggestion Total Suggestions
0 $42,439,000 5 3 3 5 0 1 1
1 $9,390,000 0 0 0 0 0 0 0
2 $9,350,000 0 0 0 0 0 0 0
3 $8,302,319 0 0 0 0 0 0 0
4 $6,125,000 0 0 0 0 0 0 0
5 $5,006,000 5 8 8 5 1 0 1
6 $4,823,000 0 0 0 0 0 0 0
7 $4,250,000 0 0 0 0 0 0 0
8 $3,810,000 0 0 0 0 0 0 0
9 $1,325,000 0 0 0 0 0 0 0
10 $1,080,000 4 10 10 4 1 0 1
11 $960,000 0 0 0 0 0 0 0
12 $931,600 0 0 0 0 0 0 0
13 $863,377 0 0 0 0 0 0 0
14 $650,000 0 0 0 0 0 0 0
15 $525,000 0 0 0 0 0 0 0
16 $491,200 0 0 0 0 0 0 0
17 $456,870 0 0 0 0 0 0 0
18 $440,000 0 0 0 0 0 0 0
19 $360,000 5 8 8 5 1 0 1
20 $341,780 0 0 0 0 0 0 0
21 $330,000 0 0 0 0 0 0 0
22 $295,000 0 0 0 0 0 0 0
23 $290,000 0 0 0 0 0 0 0
24 $284,000 0 0 0 0 0 0 0
25 $198,696 0 0 0 0 0 0 0
26 $174,369 0 0 0 0 0 0 0
27 $88,134 0 0 0 0 0 0 0
28 $88,128 0 0 0 0 0 0 0
29 $60,000 0 0 0 0 0 0 0

In [266]:
# Learn about API authentication here: https://plot.ly/pandas/getting-started
# Find your api_key here: https://plot.ly/settings/api
# Cufflinks binds plotly to pandas dataframes in IPython notebook. Read more

#sudo pip install cufflinks
#sudo pip install plotly

import plotly.plotly as py
import cufflinks as cf
import pandas as pd

py.sign_in('journProject', 'rtxpnqa904')
cf.set_config_file(offline=False, world_readable=True, theme='pearl')
Final_dataframe.iplot(kind='bubble', x='Character Typed_x', y='Order Number_x', size='Total Suggestions',
                      text='Movie Name', xTitle='Number of Characters at first occurrence',
                      yTitle='Position in suggestion list during first occurrence',
             filename='cufflinks/simple-bubble-chart')


---------------------------------------------------------------------------
PlotlyError                               Traceback (most recent call last)
<ipython-input-266-f9dd1849cf29> in <module>()
     15                       text='Movie Name', xTitle='Number of Characters at first occurrence',
     16                       yTitle='Position in suggestion list during first occurrence',
---> 17              filename='cufflinks/simple-bubble-chart')

/Users/Ramesh/anaconda/lib/python3.5/site-packages/cufflinks/plotlytools.py in _iplot(self, data, layout, filename, sharing, kind, title, xTitle, yTitle, zTitle, theme, colors, colorscale, fill, width, dash, mode, symbol, size, barmode, sortbars, bargap, bargroupgap, bins, histnorm, histfunc, orientation, boxpoints, annotations, keys, bestfit, bestfit_colors, mean, mean_colors, categories, x, y, z, text, gridcolor, zerolinecolor, margin, labels, values, secondary_y, subplots, shape, error_x, error_y, error_type, asFrame, asDates, asFigure, asImage, dimensions, asPlot, asUrl, online, **kwargs)
    916                 return py.plot(figure,sharing=sharing,filename=filename,validate=validate,auto_open=False)
    917         else:
--> 918                 return iplot(figure,sharing=sharing,filename=filename,validate=validate,online=online)
    919 
    920 

/Users/Ramesh/anaconda/lib/python3.5/site-packages/cufflinks/plotlytools.py in iplot(data_or_figure, validate, sharing, filename, online, **kwargs)
   1047                         filename='Plotly Playground {0}'.format(time.strftime("%Y-%m-%d %H:%M:%S"))
   1048 		return py.iplot(data_or_figure,validate=validate,sharing=sharing,
-> 1049 						filename=filename)
   1050 
   1051 def _ta_figure(self,**kwargs):

/Users/Ramesh/anaconda/lib/python3.5/site-packages/plotly/plotly/plotly.py in iplot(figure_or_data, **plot_options)
    149     if 'auto_open' not in plot_options:
    150         plot_options['auto_open'] = False
--> 151     url = plot(figure_or_data, **plot_options)
    152 
    153     if isinstance(figure_or_data, dict):

/Users/Ramesh/anaconda/lib/python3.5/site-packages/plotly/plotly/plotly.py in plot(figure_or_data, validate, **plot_options)
    239 
    240     plot_options = _plot_option_logic(plot_options)
--> 241     res = _send_to_plotly(figure, **plot_options)
    242     if res['error'] == '':
    243         if plot_options['auto_open']:

/Users/Ramesh/anaconda/lib/python3.5/site-packages/plotly/plotly/plotly.py in _send_to_plotly(figure, **plot_options)
   1402 
   1403     if 'error' in r and r['error'] != '':
-> 1404         raise exceptions.PlotlyError(r['error'])
   1405 
   1406     # Check if the url needs a secret key

PlotlyError: Request throttled. You've created/updated more charts than your allowed limit of 30/hour. You may either wait one hour or upgrade your account. Visit https://plot.ly/settings/subscription/ to upgrade.

In [ ]:
# Learn about API authentication here: https://plot.ly/pandas/getting-started
# Find your api_key here: https://plot.ly/settings/api
# Cufflinks binds plotly to pandas dataframes in IPython notebook. Read more

#sudo pip install cufflinks
#sudo pip install plotly

import plotly.plotly as py
import cufflinks as cf
import pandas as pd

py.sign_in('journProject', 'rtxpnqa904')
cf.set_config_file(offline=False, world_readable=True, theme='pearl')
Final_dataframe.iplot(kind='bubble', x='Character Typed_y', y='Order Number_y', size='Total Suggestions',
                      text='Movie Name', xTitle='Number of Characters used during top position',
                      yTitle='Top position suggested',
             filename='cufflinks/simple-bubble-chart')

In [ ]:
Final_plot= Final_dataframe.rename(columns={'Character Typed_x': 'char_x', 'Character Typed_y': 'char_y',
                              'Order Number_x':'order_x','Order Number_y':'order_y','Movie Name':'movie_name'})
Final_plot

In [ ]:
fig = {
    'data': [
        {'x': Final_plot.char_x, 'y': Final_plot.order_x, 'text': Final_plot.movie_name, 
         'mode': 'markers', 'name': 'Lowest Character VS Position'},
        {'x': Final_plot.char_y, 'y': Final_plot.order_y, 'text': Final_plot.movie_name, 
         'mode': 'markers', 'name': 'Highest Position VS Character'}
    ],
    'layout': {
        'xaxis': {'title': 'Number of Characters', 'type': 'log'},
        'yaxis': {'title': "Position"}
    }
}
py.iplot(fig, filename='cufflinks/multiple-scatter')

for index, row in movies_List.iterrows(): Movie_Name = row['Movie Title'] summary_data_for_results = pd.read_csv(MYFILE()+'OP'+Movie_Name+'_Summary_Filtered.csv') for s_index,s_row in summary_data_for_results.iterrows(): custom_google_search(s_row['Suggestion'])

def custom_google_search(suggestion):

url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (urllib.parse.urlencode(
            {'q': suggestion}))
search_response = requests.get(url)
results = search_response.json()
data = results['responseData']
hits = data['results']
user_ids = []
for h in hits: 
    user_ids.append(h['visibleUrl']);
    #print ('For more results, see %s' % data['cursor']['moreResultsUrl'])
print  (user_ids)   
return user_ids