Exemple #1
0
def Trump():

    if (__name__ == '__main__'):
        endpoint = 'https://api.majestic.com/api_command'

        app_api_key = '17D2EA76A0B58C5FAB0A455C320E5197'

        items_to_query = 'https://twitter.com/search?q=Trump&src=tyah'
        items = items_to_query.split(', ')

        # create a hash from the resulting array with the key being
        # 'item0 => first item to query, item1 => second item to query' etc
        parameters = {}
        for index, item in enumerate(items):
            parameters['item' + str(index)] = item

        # add the total number of items to the hash with the key being 'items'
        parameters['items'] = len(items)

        parameters['datasource'] = 'fresh'

        api_service = APIService(app_api_key, endpoint)
        response = api_service.execute_command('GetIndexItemInfo', parameters)

        # check the response code
        if (response.is_ok()):

            # print the results table
            results = response.get_table_for_name('Results')

            for row in results.rows:
                item = row['Item']
                for key in sorted(row.keys()):
                    if ('Item' != key):
                        value = row[key]
                        if (str(key) == "DownloadBacklinksAnalysisResUnitsCost"
                            ):
                            return int(value) + random.randrange(1000, 5000, 2)
Exemple #2
0
    items_to_query = raw_input()
    items = items_to_query.split(', ')

    # create a hash from the resulting array with the key being
    # 'item0 => first item to query, item1 => second item to query' etc
    parameters = {}
    for index, item in enumerate(items):
        parameters['item' + str(index)] = item
        
    # add the total number of items to the hash with the key being 'items'
    parameters['items'] = len(items)

    parameters['datasource'] = 'fresh'

    api_service = APIService(app_api_key, endpoint)
    response = api_service.execute_command('GetIndexItemInfo', parameters)

    # check the response code
    if(response.is_ok()):
        # print the results table
        results = response.get_table_for_name('Results')
        for row in results.rows:
            item = row['Item']
            print '\n<' + str(item) + '>'
            for key in sorted(row.keys()):
                if('Item' != key):
                    value = row[key]
                    print ' ' + str(key) + ' ... ' + str(value)

        if('https://developer.majestic.com/api_command' == endpoint):
Exemple #3
0
            + '\n1. API key \n2. A URL, domain or subdomain to query')

    app_api_key = raw_input('\nPlease enter your API key:\n')

    print ('\nPlease enter a URL, domain or subdomain to query:')

    item_to_query = raw_input()

    # set up parameters
    parameters = {}
    parameters['Count'] = '10'
    parameters['item'] = item_to_query
    parameters['Mode'] = '0'
    parameters['datasource'] = 'fresh'

    api_service = APIService(app_api_key, endpoint)
    response = api_service.execute_command('GetBackLinkData', parameters)

    # check the response code
    if(response.is_ok()):
        # print the URL table
        results = response.get_table_for_name('BackLinks')
        for row in results.rows:
            print ('\nURL: ' + row['SourceURL'].encode('utf-8'))
            print ('Trust Flow: ' + row['SourceTrustFlow'])

        if('https://developer.majestic.com/api_command' == endpoint):
            print ('\n\n***********************************************************'
                + '*****************')

            print ('\nEndpoint: ' + endpoint)
        + '\n(e.g. majestic.com, majestic12.co.uk)')

    items_to_query = raw_input()
    items = items_to_query.split(', ')

    # create a hash from the resulting array with the key being
    # 'item0 => first item to query, item1 => second item to query' etc
    parameters = {}
    for index, item in enumerate(items):
        parameters['item' + str(index)] = item

    # add the total number of items to the hash with the key being 'items'
    parameters['items'] = len(items)
    parameters['datasource'] = 'fresh'

    api_service = APIService(private_key, endpoint)
    response = api_service.execute_openapp_request('GetIndexItemInfo',
                                                   parameters, access_token)

    # check the response code
    if (response.is_ok()):
        # print the results table
        results = response.get_table_for_name('Results')
        for row in results.rows:
            item = row['Item']
            print '\n<' + str(item) + '>'
            for key in sorted(row.keys()):
                if ('Item' != key):
                    value = row[key]
                    print ' ' + str(key) + ' ... ' + str(value)
    items_to_query = raw_input()
    items = items_to_query.split(', ')

    # create a hash from the resulting array with the key being
    # 'item0 => first item to query, item1 => second item to query' etc
    parameters = {}
    for index, item in enumerate(items):
        parameters['item' + str(index)] = item
        
    # add the total number of items to the hash with the key being 'items'
    parameters['items'] = len(items)

    parameters['datasource'] = 'fresh'

    api_service = APIService(app_api_key, endpoint)
    response = api_service.execute_command('GetIndexItemInfo', parameters)

    # check the response code
    if(response.is_ok()):
        # print the results table
        results = response.get_table_for_name('Results')
        for row in results.rows:
            item = row['Item']
            print '\n<' + str(item) + '>'
            for key in sorted(row.keys()):
                if('Item' != key):
                    value = row[key]
                    #print(' ' + eval(repr(key).encode('utf-8')) + ' ... ' + eval(repr(value).encode('utf-8')))
                    #print ' ' + str(key) + ' ... ' + str(value)
                    print u' ... '.join((key,value))
            + '\n(e.g. majestic.com, majestic12.co.uk)')

    items_to_query = raw_input()
    items = items_to_query.split(', ')

    # create a hash from the resulting array with the key being
    # 'item0 => first item to query, item1 => second item to query' etc
    parameters = {}
    for index, item in enumerate(items):
        parameters['item' + str(index)] = item
        
    # add the total number of items to the hash with the key being 'items'
    parameters['items'] = len(items)
    parameters['datasource'] = 'fresh'

    api_service = APIService(private_key, endpoint)
    response = api_service.execute_openapp_request('GetIndexItemInfo', parameters, access_token)

    # check the response code
    if(response.is_ok()):
        # print the results table
        results = response.get_table_for_name('Results')
        for row in results.rows:
            item = row['Item']
            print '\n<' + str(item) + '>'
            for key in sorted(row.keys()):
                if('Item' != key):
                    value = row[key]
                    print ' ' + str(key) + ' ... ' + str(value)

        if('https://developer.majestic.com/api_command' == endpoint):
Exemple #7
0
def doit(url_list):

    endpoint = 'https://api.majestic.com/api_command'

    article_dict = []

    parameters = {}
    for index, item in enumerate(url_list):
        parsed_uri = urlparse(item['url'])
        domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
        article_dict.append({
            "domain": domain,
            "url": url_list[index]['url'],
            "content": url_list[index]['content']
        })
        parameters['item' + str(index)] = domain

    parameters.update({'items': len(url_list)})

    parameters.update({'datasource': 'fresh'})

    api_service = APIService(os.environ.get('MAJESTIC_API_KEY'), endpoint)
    response = api_service.execute_command('GetIndexItemInfo', parameters)

    if (response.is_ok()):
        unsorted_results = []

        results = response.get_table_for_name('Results')

        for row in results.rows:
            trustFlow = row['TrustFlow']
            item = row['Item']
            if trustFlow > 50:
                print item + " - trustflow: " + trustFlow
                unsorted_results.append({
                    'domain': item,
                    'trustFlow': trustFlow
                })

        sorted_results = sorted(unsorted_results,
                                key=lambda result: result["trustFlow"],
                                reverse=True)

        print sorted_results

        top_three = []
        top_article_urls = []

        if len(sorted_results) > 3:
            top_three = get_articles(3, sorted_results)
        else:
            top_three = get_articles(len(sorted_results), sorted_results)

        for trust_object in top_three:
            for x in range(0, len(url_list)):
                if trust_object['domain'] == article_dict[x]['domain']:
                    top_article_urls.append({
                        "url":
                        article_dict[x]['url'],
                        "content":
                        article_dict[x]['content']
                    })

        return top_article_urls