Пример #1
0
def get_search_results(query):
	if query == '':
		return random.choice(empty_query_answers)

	resp = json.loads(request.process('http://api.urbandictionary.com/v0/define', data={
		'term' : query,
		}).read().decode())
	
	results = resp['list']
	
	if not results:
		return random.choice(no_results)

	result_markup = random.choice(address_lines) + "\n"
	for res in results:
		escaped_data = escape(
			url = res['permalink'],
			word = res['word'],
			upvotes = res['thumbs_up'],
			downvotes = res['thumbs_down'],
			author = res['author'],
			definition = res['definition'],
			example = res['example']
			)
		result_markup += """
<a href="{url}" title="{url}">{word}</a> <i>Votes: +{upvotes} and -{downvotes}</i>
<small>From {author}:</small>
{definition}
Example: {example}
""".format(**escaped_data)

	return result_markup
Пример #2
0
def get_results(query):
	return json.loads(request.process('https://content.googleapis.com/dictionaryextension/v1/knowledge/search', data = {
		'language': 'en',
		'key': 'AIzaSyC9PDwo2wgENKuI8DSFOfqFqKP2cKAxxso', # consider getting your own
		'term' : query
	}, headers = {
		'X-Origin': 'chrome-extension:',
		'X-Referer': 'chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja'
	}).read().decode())
Пример #3
0
def get_search_results(query):
	if query == '':
		return random.choice(empty_query_answers)

	resp = json.loads(request.process('http://ajax.googleapis.com/ajax/services/search/web', data={
		'q' : query,
		'v' : 1.0
		}).read().decode())
	
	results = resp['responseData']['results']
	
	if not results:
		return random.choice(no_results)

	result_markup = random.choice(address_lines) + "\n"
	for res in results:
		result_markup += """
<a href="{url}" title="{tooltip}">{title}</a>
<small>@{visibleUrl}</small>
""".format(title=res['title'], url=res['url'], visibleUrl=res['visibleUrl'], tooltip=GLib.markup_escape_text(res['content']))

	return result_markup