示例#1
0
def search(query):
	if query.startswith('tt') and len(query) == 9:
		api = httplib.get_json(f'http://omdbapi.com/?i={query}&apikey={config.api.omdbapi_key}')
	else:
		year = query.split()[-1]
		if len(year) == 4 and year.isdigit():
			query = query[:-5].replace(' ', '%20')
			api = httplib.get_json(f'http://omdbapi.com/?t={query}&y={year}&apikey={config.api.omdbapi_key}')
		else:
			query = query.replace(' ', '%20')
			api = httplib.get_json(f'http://omdbapi.com/?t={query}&apikey={config.api.omdbapi_key}')
	if api['Response'] == 'True':
		return api
	else:
		return False
示例#2
0
def post_info(subreddit, id):
    api = httplib.get_json(
        f'https://www.reddit.com/r/{subreddit}/comments/{id}.json')
    if 'error' not in api:
        return api[0]['data']['children'][0]['data']
    else:
        return False
示例#3
0
def get(coin):
	api  = httplib.get_json('https://api.coinmarketcap.com/v1/ticker/?limit=500')
	data = [item for item in api if (coin.lower() == item['id'] or coin.upper() == item['symbol'])]
	if data:
		return data[0]
	else:
		return False
示例#4
0
def urban(word):
	api = httplib.get_json('http://api.urbandictionary.com/v0/define?term=' + word.replace(' ', '+'))
	if api['result_type'] != 'no_results':
		definition = api['list'][0]['definition']
		return definition
	else:
		return False
示例#5
0
def urban(word):
    api = httplib.get_json('http://api.urbandictionary.com/v0/define?term=' +
                           word.replace(' ', '+'))
    if api['result_type'] != 'no_results':
        definition = api['list'][0]['definition']
        return definition
    else:
        return False
示例#6
0
def search(query, results):
	url	    = 'https://www.googleapis.com/youtube/v3/search?part=snippet&key={0}&q={1}&maxResults={2}&type=video&regionCode=US&relevanceLanguage=en&safeSearch=none'.format(config.api.google_api_key, httplib.data_quote(query), results)
	api     = httplib.get_json(url)
	results = {}
	for item in api['items']:
		title = item['snippet']['title']
		url   = 'https://www.youtube.com/watch?v=' + item['id']['videoId']
		results[title] = url
	return results
示例#7
0
def search(query, results):
    url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&key={0}&q={1}&maxResults={2}&type=video&regionCode=US&relevanceLanguage=en&safeSearch=none'.format(
        config.api.google_api_key, httplib.data_quote(query), results)
    api = httplib.get_json(url)
    results = {}
    for item in api['items']:
        title = item['snippet']['title']
        url = 'https://www.youtube.com/watch?v=' + item['id']['videoId']
        results[title] = url
    return results
示例#8
0
def get(coin):
    api = httplib.get_json(
        'https://api.coinmarketcap.com/v1/ticker/?limit=500')
    data = [
        item for item in api
        if (coin.lower() == item['id'] or coin.upper() == item['symbol'])
    ]
    if data:
        return data[0]
    else:
        return False
示例#9
0
def lookup(zip_code):
	api = httplib.get_json('http://api.wunderground.com/api/{0}/conditions/q/{1}.json'.format(config.api.wunderground_api_key, zip_code))
	if 'error' not in api:
		city    = api['current_observation']['display_location']['city']
		state   = api['current_observation']['display_location']['state']
		country = api['current_observation']['display_location']['country']
		weather = api['current_observation']['weather']
		temp    = api['current_observation']['temp_f']
		return 'The weather for {0}, {1}, {2} is {3} at {4} F'.format(city, state, country, weather, temp)
	else:
		return False
示例#10
0
def drug(query):
    api = httplib.get_json(
        'http://tripbot.tripsit.me/api/tripsit/getDrug?name=' +
        query.replace(' ', '%20'))
    if api['err'] != True:
        return {
            'name': api['data'][0]['name'],
            'desc': api['data'][0]['properties']['summary']
        }
    else:
        return False
示例#11
0
def lookup(zip_code):
	api = httplib.get_json('http://api.wunderground.com/api/{0}/conditions/q/{1}.json'.format(config.api.wunderground_api_key, zip_code))
	if 'error' not in api:
		city    = api['current_observation']['display_location']['city']
		state   = api['current_observation']['display_location']['state']
		country = api['current_observation']['display_location']['country']
		weather = api['current_observation']['weather']
		temp    = api['current_observation']['temp_f']
		return 'The weather for {0}, {1}, {2} is {3} at {4} F'.format(city, state, country, weather, temp)
	else:
		return False
示例#12
0
def read(subreddit):
	api  = httplib.get_json('https://www.reddit.com/r/{0}.json?limit={1}'.format(subreddit, Settings.get('max_results')))
	data = [x['data'] for x in api['data']['children']]
	if data:
		results = {}
		for item in data:
			if not item['stickied']:
				results[item['title']] = {'url':item['url'], 'score':item['score'], 'ups':item['ups'], 'downs':item['downs'], 'comments':item['num_comments']}
		return results
	else:
		return False
示例#13
0
def video_info(id):
	api = httplib.get_json(f'https://www.googleapis.com/youtube/v3/videos?key={config.api.google_api_key}&part=snippet,statistics&id={id}')
	if api['items']:
		api                 = api['items'][0]
		data                = {}
		data['channel']     = api['snippet']['channelTitle']
		data['description'] = ' '.join(api['snippet']['description'].split())
		data['dislikes']    = api['statistics']['dislikeCount']
		data['likes']       = api['statistics']['likeCount']
		data['title']       = api['snippet']['title']
		data['views']       = api['statistics']['viewCount']
		return data
	else:
		return False
示例#14
0
def video_info(id):
    api = httplib.get_json(
        f'https://www.googleapis.com/youtube/v3/videos?key={config.api.google_api_key}&part=snippet,statistics&id={id}'
    )
    if api['items']:
        api = api['items'][0]
        data = {}
        data['channel'] = api['snippet']['channelTitle']
        data['description'] = ' '.join(api['snippet']['description'].split())
        data['dislikes'] = api['statistics']['dislikeCount']
        data['likes'] = api['statistics']['likeCount']
        data['title'] = api['snippet']['title']
        data['views'] = api['statistics']['viewCount']
        return data
    else:
        return False
示例#15
0
def post_info(subreddit, id):
	api = httplib.get_json(f'https://www.reddit.com/r/{subreddit}/comments/{id}.json')
	if 'error' not in api:
		return api[0]['data']['children'][0]['data']
	else:
		return False
示例#16
0
def drug(query):
	api = httplib.get_json('http://tripbot.tripsit.me/api/tripsit/getDrug?name=' + query.replace(' ','%20'))
	if api['err'] != True:
		return {'name':api['data'][0]['name'],'desc':api['data'][0]['properties']['summary']}
	else:
		return False