• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shorteners.Shortener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_google_bad_params

def test_google_bad_params():
    s = Shortener('GoogleShortener')

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

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


示例2: test_googl_shortener

    def test_googl_shortener(self):
        engine = 'GoogleShortener'
        short = Shortener(engine)
        self.assertEqual(short.short('http://www.google.com'),
                         'http://goo.gl/fbsS')

        self.assertEqual(short.expand('http://goo.gl/fbsS'),
                         'http://www.google.com/')
开发者ID:relsi,项目名称:pyshorteners,代码行数:8,代码来源:test_shorteners.py


示例3: test_tinyurl_shortener

    def test_tinyurl_shortener(self):
        engine = 'TinyurlShortener'
        short = Shortener(engine)
        self.assertEqual(short.short('http://www.google.com'),
                         'http://tinyurl.com/1c2')

        self.assertEqual(short.expand('http://tinyurl.com/ycus76'),
                         'https://www.facebook.com')
开发者ID:relsi,项目名称:pyshorteners,代码行数:8,代码来源:test_shorteners.py


示例4: test_generic_expander

    def test_generic_expander(self):
        # testing new generic expander. Uses another shortener to test
        short = Shortener("TinyurlShortener")
        shorten = short.short(self.test_url)

        engine = "GenericExpander"
        expander = Shortener(engine)
        result_url = expander.expand(shorten)
        # A valid url result is enough for answer
        self.assertEqual(result_url, self.test_url)
开发者ID:MaximilianoRios,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py


示例5: test_qrcx_shortener

    def test_qrcx_shortener(self):
        engine = 'QrCxShortener'
        short = Shortener(engine)
        url = 'https://www.facebook.com/'

        shorten = short.short(url)
        expand = short.expand(shorten)
        self.assertEqual(expand, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py


示例6: test_sentala_shortener

    def test_sentala_shortener(self):
        engine = 'SentalaShortener'
        short = Shortener(engine)
        url = 'http://www.pilgrims.com'

        shorten = short.short(url)
        expand = short.expand(shorten)
        self.assertEqual(expand, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py


示例7: url_shortener

def url_shortener(url):
    '''Shorten url through google api
      :param url: url to be shortened, with urlencode
      :param SHORTENER_API_KEY: goo.gl shortener key
    '''

    from pyshorteners.shorteners import Shortener
    shortener = Shortener('GoogleShortener', api_key=os.environ['SHORTENER_API_KEY'])
    short_url = shortener.short(url)
    return short_url
开发者ID:WadiInternet,项目名称:wadutils,代码行数:10,代码来源:app.py


示例8: test_is_valid_url

    def test_is_valid_url(self):
        bad = 'www.google.com'
        good = 'http://www.google.com'

        self.assertTrue(is_valid_url(good))
        self.assertFalse(is_valid_url(bad))

        s = Shortener('TinyurlShortener')
        with self.assertRaises(ValueError):
            url = 'http://12'
            s.short(url)
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:11,代码来源:test_shorteners.py


示例9: test_adfly_shortener

    def test_adfly_shortener(self):
        engine = 'AdflyShortener'
        short = Shortener(engine, key='abcd', uid='123')
        url = 'http://www.google.com/'

        short.short = MagicMock(return_value='http://adf.ly/test')
        short.short(url)
        short.short.assert_called_with(url)

        expand = short.expand('http://adf.ly/test')
        self.assertEqual(expand, 'http://adf.ly/test')
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:11,代码来源:test_shorteners.py


示例10: minify_callback

def minify_callback(word, word_eol, userdata):
    shorty = Shortener('Isgd')
    words = word_eol[0].split() # word_eol[0] is the full text message
    finalwords = ''
    for word in words:
        if validators.url(word):
            word = shorty.short(word)
        finalwords += word + ' ' 
    currentchannel = hexchat.get_info('channel')
    hexchat.command("MSG  " + currentchannel + " " + finalwords)
    return hexchat.EAT_ALL
开发者ID:madnight,项目名称:hexchat-addons,代码行数:11,代码来源:minify.py


示例11: test_dottk_shortener

    def test_dottk_shortener(self):
        engine = 'DottkShortener'
        short = Shortener(engine)
        url = 'http://www.google.com/'

        short.short = MagicMock(return_value='http://3vzpu.tk')
        short.short(url)
        short.short.assert_called_with(url)

        expand = short.expand('http://adf.ly/test')
        self.assertEqual(expand, 'http://adf.ly/test')
开发者ID:relsi,项目名称:pyshorteners,代码行数:11,代码来源:test_shorteners.py


示例12: test_tinyurl_shortener

    def test_tinyurl_shortener(self):
        engine = 'TinyurlShortener'
        short = Shortener(engine)
        url = 'http://tinyurl.com/nc9m936'
        shorten = short.short(self.test_url)
        self.assertEqual(shorten, url)

        self.assertEqual(short.expand(), self.test_url)
        self.assertEqual(short.expand(url), self.test_url)

        self.assertEqual(short.expanded, self.test_url)
        self.assertEqual(short.shorten, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:14,代码来源:test_shorteners.py


示例13: main

def main():
    args = parse_args()
    targetlist = ""
    colorpairs = 0
    for target in args.tests:
        targets = get_targets(target, COLORS[colorpairs % len(COLORS)],
                              avg=args.smoothing)
        colorpairs += 1
        subtarglist = "&".join(targets)
        targetlist = "&".join([targetlist, subtarglist])
    url = "&".join((
        graphite_base_url(args.duration, args.smoothing), targetlist))
    webbrowser.open(url)
    shortener = Shortener('TinyurlShortener')
    print "URL for sharing: %s" % shortener.short(url)
开发者ID:umago,项目名称:failopotamus,代码行数:15,代码来源:failgraph.py


示例14: test_readability_shortener

    def test_readability_shortener(self):
        engine = 'ReadabilityShortener'
        short = Shortener(engine)
        url = 'http://blog.arc90.com/2010/11/30/silence-is-golden/'
        short_url = 'http://rdd.me/tg8if9uj'
        readbility_url = 'http://readability.com/articles/tg8if9uj'
        shorten = short.short(url)
        self.assertEqual(shorten, short_url)

        expand = short.expand(shorten)
        self.assertEqual(expand, readbility_url)

        # Test wrong url_id
        short = Shortener(engine)
        with self.assertRaises(ExpandingErrorException):
            expand = short.expand('http://www.wqe.cc')
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:16,代码来源:test_shorteners.py


示例15: send_text

def send_text(title, link):

        url = str(link)
        shortener = Shortener('TinyurlShortener') 
        print "My short url is {}".format(shortener.short(url))
        text_link = format(shortener.short(url))

        text_body = "Price has lowered for " + title + " " + text_link

        client.messages.create(
            to="3153825951",
            from_="+14159643618",
            body=text_body,
        )

        print "Sent text"
开发者ID:eluckette,项目名称:price-ping,代码行数:16,代码来源:check_prices_demo.py


示例16: RSSPlugin

class RSSPlugin(BotPlugin):
    RSS_MSG_FORMAT = '{0} > {1} > {2}'

    def setup(self, *args, **kwargs):
        self.storage = self.open_storage('rss')
        self.feeds = self.config['feeds']
        self.max_stories = int(self.config.get('max_stories', 5))
        self.update_interval = int(self.config.get('update_interval', 30))
        self.max_link_length = int(self.config.get('max_link_length', 50))
        self.entry_cache_size = int(self.config.get('entry_cache_size', 100))

        self.shortener = Shortener('IsgdShortener')

        for feed in self.feeds:
            if feed not in self.storage:
                self.storage[feed] = []
        self.loop_task(self.update_interval, self.check_feeds, now=False)

    def hash_entry(self, entry):
        """Creates a hash out of the feedparser's Entry. Uses just the title
        and the link as that is what we care about in most cases."""
        return hashlib.sha224("{}{}".format(entry.title,
                                            entry.link)).hexdigest()

    def check_feeds(self):
        """"Periodically checks for new entries in given (configured) feeds."""
        for feed in self.feeds:
            d = feedparser.parse(feed)
            past_entries = self.storage[feed]

            i = 1
            for entry in d.entries:
                hash = self.hash_entry(entry)
                if hash in past_entries:
                    continue

                if i > self.max_stories:
                    break

                self.delay_task(i, self.sender(d, entry))
                i += 1
                past_entries.insert(0, hash)
            self.storage[feed] = past_entries[:self.entry_cache_size]
        return ''

    def sender(self, d, entry):
        """A helper function that takes care of sending the entry that we
        regard as 'new' to proper places. Moreover, it takes care of formatting
        the raw entry into textual representation and shortening the entry
        link if it is too long."""
        link = entry.link
        if len(link) > self.max_link_length:
            link = self.shortener.short(link)

        s = self.RSS_MSG_FORMAT.format(d.feed.title,
                                       entry.title,
                                       link)
        self.msg(s)
开发者ID:mrshu,项目名称:brutal-plugins,代码行数:58,代码来源:rss.py


示例17: setup

    def setup(self, *args, **kwargs):
        self.storage = self.open_storage('rss')
        self.feeds = self.config['feeds']
        self.max_stories = int(self.config.get('max_stories', 5))
        self.update_interval = int(self.config.get('update_interval', 30))
        self.max_link_length = int(self.config.get('max_link_length', 50))
        self.entry_cache_size = int(self.config.get('entry_cache_size', 100))

        self.shortener = Shortener('IsgdShortener')

        for feed in self.feeds:
            if feed not in self.storage:
                self.storage[feed] = []
        self.loop_task(self.update_interval, self.check_feeds, now=False)
开发者ID:mrshu,项目名称:brutal-plugins,代码行数:14,代码来源:rss.py


示例18: test_bitly_shortener

    def test_bitly_shortener(self):
        engine = 'BitlyShortener'
        short = Shortener(engine, bitly_api_key='abc', bitly_login='123x')
        url = 'http://www.google.com/'
        short_url = 'http://bit.ly/xxx'
        short.short = MagicMock(return_value='http://bit.ly/SsdA')
        short.short(url)
        short.short.assert_called_with(url)

        #expanding
        short.expand = MagicMock(return_value=url)
        short.expand(short_url)
        short.expand.assert_called_with(short_url)
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:13,代码来源:test_shorteners.py


示例19: test_bitly_shortener

    def test_bitly_shortener(self):
        engine = 'BitlyShortener'
        short = Shortener(engine, bitly_api_key='abc', bitly_login='123x')
        url = 'http://www.google.com/'
        short_url = 'http://bit.ly/xxx'

        # test with no mock
        with self.assertRaises(ShorteningErrorException):
            short = short.short(url)

        # mocking the results
        short.expand = MagicMock(return_value=url)
        short.short = MagicMock(return_value='http://bit.ly/SsdA')

        short.short(url)
        short.short.assert_called_with(url)
        short.expand(short_url)
        short.expand.assert_called_with(short_url)

        # test with no key params
        with self.assertRaises(TypeError):
            short = Shortener(engine).short('http://www.google.com')
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:22,代码来源:test_shorteners.py


示例20: test_generic_expander

    def test_generic_expander(self):
        # testing new generic expander. Uses another shortener to test
        short = Shortener("TinyurlShortener")
        shorten = short.short(self.test_url)

        engine = "GenericExpander"
        expander = Shortener(engine)

        with self.assertRaises(NotImplementedError):
            expander.short('http://www.test.com')

        result_url = expander.expand(shorten)
        # A valid url result is enough for answer
        self.assertEqual(result_url, self.test_url)
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:14,代码来源:test_shorteners.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pysideuic.compileUi函数代码示例发布时间:2022-05-26
下一篇:
Python pyshorteners.Shortener类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap