示例#1
0
import blockspring

def block(request, response):
	to_return = [[1],[2],[3],[4]]


    local_change = 2

    remote_change = 2


	response.addOutput("array", to_return)
	response.end()

blockspring.define(block)
            /li/a/span[@class="text"]/text()'
    url = ''.join(['http://www.thesaurus.com/browse/', word])
    page = requests.get(url)
    tree = html.fromstring(page.text)
    word_info_map['antonyms'] = tree.xpath(XPATH)

# END RETRIEVAL AND INTEGRATION HELPER FUNCTIONS


# BEGIN CLIENT-FACING (API) FUNCTIONS

def block(request, response):
    '''
        Write information about the specified word (provided in "request")
        to "response." "request" may also contain filters that specify which
        information should/should not be included in the "response."
    '''
    # Collect all of the information for the specified word.
    word_info = _get_info_from_merriam_webster(request)
    _add_antonyms_from_thesaurus_com(request, word_info)

    for info in word_info.keys():
        response.addOutput(info, word_info[info])

    response.end()

blockspring.define(block)

# END CLIENT-FACING (API) FUNCTIONS

示例#3
0
    columns = [first_key] + inner_keys['_holdings_']
    
    #start building return array with column headers as first row
    to_return = [columns]

    #add a row for each holding
    for date in results.keys():
        holdings = results[date]['_holdings_']
        for holding in holdings:
            row = []
            row.append(date)
            #add date to first column in row
            keys_to_check = columns[1:]
            for key in keys_to_check:
                if key in holding:
                    row.append(holding[key])
                else:
                    row.append(0)

            to_return.append(row)


    response.addOutput("results", to_return)

    ## Return the response
    response.end()

## Defining get_13f_data function for blockspring
blockspring.define(get_13f_data)
示例#4
0
    write_status = []

    ## Index each row as a document
    for row in rows:
        ## Create a dictionary with the clean labels to index
        doc = dict(zip(properties, row))

        ## Adding timestamp to the document
        doc['indexed_at'] = str(int(datetime.now().strftime("%s")))

        ## Build the URL and index the dictionary as a JSON document in elasticsearch
        url = address + '/' + index + '/' + datatype + '/'
        json_doc = dumps(doc)
        req = requests.post(url, json_doc)

        ## Keep track of which writes were sucessful 

        if req.ok == True:
             write_status.append([url, json_doc, 'True'])
        else:
            write_status.append([url, json_doc, 'Fail'])

        ##Add array of statuses to response 
        response.addOutput("Indexed", write_status)

    ## Return the response
    response.end()

## Defining write_to_es function for blockspring
blockspring.define(write_table_to_es)
示例#5
0
                columns = es_internal_stuff + fields_in_docs
                results.append(columns)
                for result in query_response["hits"]["hits"]:
                    row = []
                    for key in columns:
                        if key in set(es_internal_stuff):
                            row.append(result[key])
                        else:
                            if key in result["_source"]:
                                row.append(result["_source"][key])
                            else:
                                row.append(0)
                    results.append(row)
            else:
                results.append(["no hits"])
        else:
            results.append(["no hits"])
    else:
        results.append(["ERROR", req.reason])

    ##Add array of statuses to response
    response.addOutput("results", results)

    ## Return the response
    response.end()


## Defining write_to_es function for blockspring
blockspring.define(read_table_from_es)