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
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
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
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
def search(query, results): url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&key={0}&q={1}&maxResults={2}&type=video®ionCode=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
def search(query, results): url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&key={0}&q={1}&maxResults={2}&type=video®ionCode=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
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
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
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
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
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
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
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
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