Example #1
0
def Convert2JSON(gsobj, skinny = True):
    # Return JSON
    if skinny:
        results = ''
    else:
        results = '['

    for serp in gsobj.serps:
        data = row2dict(serp)
        data['results'] = []
        for link in serp.links:
            data['results'].append(row2dict(link))
        if skinny:
            recordJSON = json.dumps(data['results'])
            # Remove '[' and ']' at each ends
            if recordJSON.strip() != '':
                if recordJSON.startswith('['):
                    recordJSON = recordJSON[1:-1]
                if results != '':
                    results += ', '
                results += recordJSON
        else:
            recordJSON = json.dumps(data, indent=2, sort_keys=True)
            if recordJSON.strip() != '':
                if results != '[':
                    results += ', '
                results += recordJSON

    if not skinny:
        results += ']'

    return results
Example #2
0
def Convert2Dictionary(gsobj):
    # Dictionary
    results = []

    for serp in gsobj.serps:
        for link in serp.links:
            results.append(row2dict(link))

    return results
Example #3
0
def PageRankingExpress(gsobj):
    # Array
    results = []
    baserank = 1000

    for serp in gsobj.serps:
        if not serp.no_results:
            for link in serp.links:
                # Re-ranking
                baserank+=1
                if link.link_type != 'ads_main':
                    link.rank = pageranker.rank(link.domain, link.link, link.link_type, baserank, link.title)
                    results.append(row2dict(link))
                    # ToDo: We may also need to filter and reorder the list
                    # SBS: let's do it in client side by using AngularJS

    return results