def searchTest(): s = '' with open('/opt/bitly_test_data') as f: for line in f: s += line d = json.loads(s) links = d['data']['results'] frequencies = chainlink_util.get_freqs(links) top_word = max(frequencies.iteritems(), key=operator.itemgetter(1))[0] ret = {'words':frequencies, 'top_word':top_word, 'title': 'cybersecurity', } return json.dumps(ret)
def search(keyword,number): print keyword try: b = bitly_api.Connection(access_token=BitlyConf.get_access_token()) links = b.search(keyword,limit=number) except bitly_api.BitlyError as e: print e return e print len(links) #build the return elements frequencies = chainlink_util.get_freqs(links) #calculate metadata top_word = max(frequencies.iteritems(), key=operator.itemgetter(1))[0] ret = {'words':frequencies, 'top_word':top_word, 'title':keyword or "No Term Given", } return json.dumps(ret)