当前位置: 首页>>代码示例>>Python>>正文


Python Shortener.short方法代码示例

本文整理汇总了Python中pyshorteners.Shortener.short方法的典型用法代码示例。如果您正苦于以下问题:Python Shortener.short方法的具体用法?Python Shortener.short怎么用?Python Shortener.short使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyshorteners.Shortener的用法示例。


在下文中一共展示了Shortener.short方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_owly_bad_key

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_owly_bad_key():
    b = Shortener(shorteners.OWLY_SHORTENER)
    with pytest.raises(TypeError):
        b.short('http://www.test.com')

    with pytest.raises(TypeError):
        b.expand('http://www.test.com')
开发者ID:ShaneDiNozzo,项目名称:pyshorteners,代码行数:9,代码来源:test_owly.py

示例2: test_owly_bad_key

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_owly_bad_key():
    b = Shortener('OwlyShortener')
    with pytest.raises(TypeError):
        b.short('http://www.test.com')

    with pytest.raises(TypeError):
        b.expand('http://www.test.com')
开发者ID:Rudddi,项目名称:pyshorteners,代码行数:9,代码来源:test_owly.py

示例3: test_google_bad_params

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_google_bad_params():
    s = Shortener(Shorteners.GOOGLE)

    with pytest.raises(TypeError):
        s.short(expanded)

    with pytest.raises(TypeError):
        s.expand(expanded)
开发者ID:Oire,项目名称:pyshorteners,代码行数:10,代码来源:test_googl.py

示例4: test_bitly_bad_keys

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_bitly_bad_keys():
    s = Shortener(Shorteners.BITLY)

    with pytest.raises(TypeError):
        s.short(expanded)

    with pytest.raises(TypeError):
        s.expand(shorten)
开发者ID:Oire,项目名称:pyshorteners,代码行数:10,代码来源:test_bitly.py

示例5: test_qrcode

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_qrcode():
    s = Shortener('TinyurlShortener')
    url = 'http://www.google.com'
    mock_url = '{}?url={}'.format(s.api_url, url)
    shorten = 'http://tinyurl.com/test'
    responses.add(responses.GET, mock_url, body=shorten,
                  match_querystring=True)
    s.short(url)
    # flake8: noqa
    assert s.qrcode() == 'http://chart.apis.google.com/chart?cht=qr&chl={0}&chs=120x120'.format(shorten)
开发者ID:Rudddi,项目名称:pyshorteners,代码行数:12,代码来源:test_shorteners.py

示例6: test_shortener_debug_enabled

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_shortener_debug_enabled():
    url = 'http://www.test.com'
    small = 'http://small.com'
    responses.add(responses.GET, url, body=small)
    responses.add(responses.GET, small, body=url)

    s = Shortener(debug=True)
    s.short('http://www.test.com')
    s.expand('http://small.com')
    with pytest.raises(NotImplementedError):
        s.total_clicks('http://small.com')
开发者ID:Rudddi,项目名称:pyshorteners,代码行数:13,代码来源:test_shorteners.py

示例7: url_shorten

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def url_shorten(service, url):

    supported_services = ['Isgd']
    url = url if url.startswith('http') else ('http://%s' % url)

    if service not in supported_services:
        print 'Service "{}" is not supported, supported services are: {}'\
            .format(service, supported_services)
        return
    try:
        shortener = Shortener(service)
        print shortener.short(url)
    except ValueError:
        print 'Invalid url given'
    except Exception as e:
        print 'Unable to shorten the url'
开发者ID:ivaano,项目名称:shell_url_shortener,代码行数:18,代码来源:urlshort.py

示例8: item_create

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def item_create(form):
    record = db(db.geo_item.f_name == request.vars.f_name).select().first()
    if record.f_qrcode == None:
        arg = str(record.id)
        path = 'http://siri.pythonanywhere.com/byui_art/default/item_details?itemId=' + arg + '&qr=True'
        tiny = ""
        shortSuccess = False
        try:
            shortener = Shortener('Tinyurl')
            tiny = "{}".format(shortener.short(path))
            session.tinyCreateException = tiny
            shortSuccess = True
        except:
            session.tinyCreateException = "There was a problem with the url shortener. Please try again."

        if shortSuccess:
            code = qrcode.make(tiny)
        else:
            code = qrcode.make(path)
        qrName='geo_item.f_qrcode.%s.jpg' % (uuid.uuid4())
        code.save(request.folder + 'uploads/qrcodes/' + qrName, 'JPEG')
        record.update_record(f_qrcode=qrName)
        qr_text(qrName, record.f_name, record.f_alt5, tiny)
    try:
        imgPath = request.folder + 'uploads/' + record.f_image
        thumbName = 'geo_item.f_thumb.%s.%s.jpg' % (uuid.uuid4(), record.id)
        thumb = Image.open(request.folder + 'uploads/' + record.f_image)
        thumb.thumbnail((350, 10000), Image.ANTIALIAS)
        thumb.save(request.folder + 'uploads/thumbs/' + thumbName, 'JPEG')
        record.update_record(f_thumb=thumbName)
    except:
        session.itemCreateException = "there was a problem updating the image in item_create: " + record.f_name
    return dict()
开发者ID:siricenter,项目名称:byui_art,代码行数:35,代码来源:cms.py

示例9: coll_create

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def coll_create(form):
    record = db(db.geo_collection.f_name == request.vars.f_name).select().first()
    arg = str(record.id)
    path = 'http://siri.pythonanywhere.com/byui_art/default/collection_details?collectionId=' + arg + '&qr=True'
    tiny = ""
    #######################################################################
    ################## TESTING PYSHORTENERS : TINYURL #####################
    #######################################################################
    
    try:
        shortener = Shortener('TinyurlShortener')
        tiny = "{}".format(shortener.short(path))
    except:
        session.tinyCreateException = "There was a problem with the url shortener. Please try again."
    
    #######################################################################
    ###################### END PYSHORTENERS : TINYURL #####################
    #######################################################################
    

    
    code = qrcode.make(tiny)
    qrName='geo_collection.f_qrcode.%s.jpg' % (uuid.uuid4())
    code.save(request.folder + 'uploads/qrcodes/' + qrName, 'JPEG')
    qr_text(qrName, record.f_name, record.f_location, tiny)
    record.update_record(f_qrcode=qrName)
    return dict()
开发者ID:siricenter,项目名称:byui_art,代码行数:29,代码来源:cms.py

示例10: test_is_valid_url

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_is_valid_url():
    bad = 'www.google.com'
    good = 'http://www.google.com'

    assert is_valid_url(good)
    assert not is_valid_url(bad)

    s = Shortener('TinyurlShortener')
    with pytest.raises(ValueError):
        url = 'http://12'
        s.short(url)


    with pytest.raises(ValueError):
        url = 'www.11.xom'
        s.expand(url)
开发者ID:Rudddi,项目名称:pyshorteners,代码行数:18,代码来源:test_shorteners.py

示例11: get_item_str

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
    def get_item_str(self, item):
        global api_key
        global cache
        global shortener_service

        if api_key:
            shortener = Shortener(shortener_service, api_key=api_key)
        else:
            shortener = None

        short_url = None
        if cache is not None:
            short_url = cache.get(item['link'])
        if short_url is None:
            # Retry 3 times for goo.gl API
            for i in range(0,3):
                try:
                    short_url = shortener.short(item['link'])
                    if short_url is not None:
                        logger.debug("Saving short url to cache")
                        cache.put(item['link'], short_url)
                except Exception as e:
                    logger.debug("Shortener threw exception {}".format(e.message))
                    continue
                break
        else:
            logger.debug("Short url cache hit")
        if short_url is None:
            url = item['link']
        else:
            url = short_url
        return '[%s] %s <%s>' % (''.join([c for c in self.name][0:18]), item['title'], url)
开发者ID:Mustaavalkosta,项目名称:pyfibot,代码行数:34,代码来源:module_rss.py

示例12: tweet_post

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def tweet_post(title, url, subid):
   
    #post found scores to twitter
    CONSUMERKEY = keys[0]
    CONSUMERSECRET = keys[1]
    ACCESSKEY = keys[2]
    ACCESSSECRET = keys[3]
    
    nonDuplicateFlag = True
    
    auth = tweepy.OAuthHandler(CONSUMERKEY, CONSUMERSECRET)
    auth.set_access_token(ACCESSKEY, ACCESSSECRET)
    api = tweepy.API(auth)

    #Clean link to prepare for tweeting
    title = tweet_cleanup(title)
   
    shortener = Shortener('TinyurlShortener')
    tinyurl = shortener.short(url)
    tweet = tweet_cleanup(title)
   
    if subid in postedTweets:
        nonDuplicateFlag = False
        return
    
    post = title + tinyurl

    try:
        api.update_status(post) #post the tweet
    except:
        print('Tweet not posted. Check Issue. Length= ', len(post))
        return

    postedTweets.append(subid)
    update_db()
开发者ID:anmousyon,项目名称:python,代码行数:37,代码来源:lolreddit.py

示例13: test_custom_shortener

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def test_custom_shortener():
    class MyShortenerWithBlackJackAndHookers(BaseShortener):
        def short(self, url):
            return url

    s = Shortener(MyShortenerWithBlackJackAndHookers)
    url = 'http://www.test.com'
    assert s.short(url) == url
开发者ID:paullo0106,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py

示例14: hello

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def hello():
    short = Shortener('Tinyurl')
    print("""
Hello World! Testing TinyurlShortener with www.google.com URL
Shorten url: {}
Expanded: {}
    """.format(short.short('http://www.google.com'),
               short.expand('http://goo.gl/fbsS')))
开发者ID:Oire,项目名称:pyshorteners,代码行数:10,代码来源:example.py

示例15: hello

# 需要导入模块: from pyshorteners import Shortener [as 别名]
# 或者: from pyshorteners.Shortener import short [as 别名]
def hello():
    googl = Shortener('GoogleShortener')

    return """
    Hello World! Testing www.google.com
    Shorten url:{} - Expanded:{}
    """.format(googl.short('http://www.google.com'),
               googl.expand('http://goo.gl/fbsS')),
开发者ID:arthurfurlan,项目名称:pyshorteners,代码行数:10,代码来源:example.py


注:本文中的pyshorteners.Shortener.short方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。