コード例 #1
0
    def __init__(self, name):
        self._name = name
        config = ConfigParser()
        config.read('{0}.cfg'.format(self._name))

        oauth_token = config.get('Twitter', 'oauth_token')
        oauth_secret = config.get('Twitter', 'oauth_secret')
        consumer_key = config.get('Twitter', 'consumer_key')
        consumer_secret = config.get('Twitter', 'consumer_secret')

        self._twitter = Twitter(auth=OAuth(oauth_token, oauth_secret,
                                           consumer_key, consumer_secret))

        access_token = config.get('bitly', 'access_token')
        self._bitly = Connection(access_token=access_token)
コード例 #2
0
 def url_shorten(self):
     #checking if the user entered the url
     #getting the entered url from the entered text variable of myentry
     self.urladdress = self.entered_url.get()
     #putting the token generated from bitly
     self.token1 = "6070e50a9fa9f917ffcf54311c8813227a562dc2"
     #we create the connection and access the bitly using the token
     try:
         self.api1 = Connection(access_token=self.token1)
         #now shorting the url using bitly
         self.response = self.api1.shorten(self.urladdress)
         # setting the received response to display on our label
         self.shortened_url.set(self.response['url'])
     except urllib.HTTPError:
         time.sleep(10)
         self.shortened_url.set("Poor or No intenet connection")
コード例 #3
0
def shorten_url(url):
    c = Connection(login=os.environ.get('BITLY_LOGIN'),
                   api_key=os.environ.get('BITLY_API_KEY'))
    return c.shorten(url)['url']
コード例 #4
0
ファイル: bitly.py プロジェクト: tosky/did
 def api(self):
     if not self._connection:
         self._connection = Connection(access_token=self.token)
     return self._connection
コード例 #5
0
load_dotenv('.env')

log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=log_format)
logger = logging.getLogger(__name__)

BITLY_DOMAIN = os.environ['BITLY_DOMAIN']
BITLY_GROUP_GUID = os.environ['BITLY_GROUP_GUID']

if __name__ == '__main__':

    logger.debug('Logger Initialized')
    logger.debug('Testing Bitly Api wrapper')

    bitly = Connection(access_token=os.environ['BITLY_ACCESS_TOKEN'])

    bitlink = bitly.bitlink('kpiq.io/2NyA91a')

    links = bitly.group_bitlinks(BITLY_GROUP_GUID,
                                 query='http://www.example.com')

    link = bitly.link_lookup('http://www.example.com/', links)

    logger.debug('Bitly Search Results:')
    logger.debug(links)

    short_url = bitly.shorten('http://www.example.com', BITLY_DOMAIN,
                              BITLY_GROUP_GUID)

    logger.debug('Short URL:')