def onLoad(self): self.handledExternally = {} """@type : dict[str, list[str]]""" # dict of regex patterns not to follow. populated by other modules so they can handle them themselves self.youtubeKey = load_key(u'YouTube') self.imgurClientID = load_key(u'imgur Client ID')
def onLoad(self): self.handledExternally = {} """@type : dict[str, list[str]]""" # dict of regex patterns not to follow. populated by other modules so they can handle them themselves self.youtubeKey = load_key(u'YouTube') self.imgurClientID = load_key(u'imgur Client ID') self.autoFollow = True
def googleSearch(query): """ @type query: unicode @rtype: dict[unicode, T] """ googleKey = load_key(u'Google') service = build('customsearch', 'v1', developerKey=googleKey) res = service.cse().list(q=query, cx='002603151577378558984:xiv3qbttad0').execute() return res
def _get_access_token(self): """Obtain a bearer token.""" consumer_key = api_keys.load_key("Twitter Key") consumer_secret = api_keys.load_key("Twitter Secret") if consumer_key is None or consumer_secret is None: raise TwitterAPIKeysMissing('Twitter API Keys are missing, cannot use Twitter API') bearer_token = '%s:%s' % (consumer_key, consumer_secret) encoded_bearer_token = base64.b64encode(bearer_token.encode('ascii')) request = Request('https://api.twitter.com/oauth2/token') request.add_header('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8') request.add_header('Authorization', 'Basic %s' % encoded_bearer_token.decode('utf-8')) request.add_data('grant_type=client_credentials'.encode('ascii')) response = urlopen(request) raw_data = response.read().decode('utf-8') data = json.loads(raw_data) return data['access_token']
def googleSearch(query): """ @type query: unicode @rtype: dict[unicode, T] """ googleKey = load_key(u'Google') service = build('customsearch', 'v1', developerKey=googleKey) res = service.cse().list( q = query, cx = '002603151577378558984:xiv3qbttad0' ).execute() return res
def _get_access_token(self): """Obtain a bearer token.""" consumer_key = api_keys.load_key("Twitter Key") consumer_secret = api_keys.load_key("Twitter Secret") if consumer_key is None or consumer_secret is None: raise TwitterAPIKeysMissing( 'Twitter API Keys are missing, cannot use Twitter API') bearer_token = '%s:%s' % (consumer_key, consumer_secret) encoded_bearer_token = base64.b64encode(bearer_token.encode('ascii')) request = Request('https://api.twitter.com/oauth2/token') request.add_header('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8') request.add_header('Authorization', 'Basic %s' % encoded_bearer_token.decode('utf-8')) request.add_data('grant_type=client_credentials'.encode('ascii')) response = urlopen(request) raw_data = response.read().decode('utf-8') data = json.loads(raw_data) return data['access_token']
def shortenGoogl(url): """ @type url: unicode @rtype: unicode """ post = '{{"longUrl": "{}"}}'.format(url) googlKey = load_key(u'goo.gl') if googlKey is None: return "[goo.gl API key not found]" apiURL = 'https://www.googleapis.com/urlshortener/v1/url?key={}'.format(googlKey) headers = {"Content-Type": "application/json"} try: request = Request(apiURL, post, headers) response = json.loads(urlopen(request).read()) return response['id'] except Exception, e: print "Goo.gl error: %s" % e
def shortenGoogl(url): """ @type url: unicode @rtype: unicode """ post = '{{"longUrl": "{}"}}'.format(url) googlKey = load_key(u'goo.gl') if googlKey is None: return "[goo.gl API key not found]" apiURL = 'https://www.googleapis.com/urlshortener/v1/url?key={}'.format( googlKey) headers = {"Content-Type": "application/json"} try: request = Request(apiURL, post, headers) response = json.loads(urlopen(request).read()) return response['id'] except Exception, e: print "Goo.gl error: %s" % e
def onLoad(self): self.imgurClientID = load_key(u"imgur Client ID") self.headers = [("Authorization", "Client-ID {}".format(self.imgurClientID))]
def onLoad(self): self.api_key = load_key(u'Bing Maps')
def onLoad(self): self.imgurClientID = load_key(u'imgur Client ID') self.headers = [('Authorization', 'Client-ID {}'.format(self.imgurClientID))]
def onLoad(self): self.youtubeKey = load_key(u'YouTube') self.imgurClientID = load_key(u'imgur Client ID')