本文整理汇总了Python中pyshorteners.shorteners.Shortener类的典型用法代码示例。如果您正苦于以下问题:Python Shortener类的具体用法?Python Shortener怎么用?Python Shortener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shortener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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/')
示例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')
示例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)
示例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))
示例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))
示例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
示例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)
示例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')
示例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
示例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')
示例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))
示例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)
示例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')
示例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"