@@ -56,34 +56,29 @@ import bitlyshortener
5656# Setup
5757tokens_pool = [' 9fbe2864bb8872f5027c103321ff91be90aea687' , ' 0cbe3864bc8872f5027c103321ff91be30aea787' ] # Use your own.
5858shortener = bitlyshortener.Shortener(tokens = tokens_pool, max_cache_size = 256 )
59- vanity_shortener = bitlyshortener.Shortener(tokens = tokens_pool, max_cache_size = 256 , vanitize = True ) # vanity=True keeps custom vanity domains when available.
6059
6160# Shorten to list
6261long_urls = [' https://www.amazon.com/gp/product/B07LFJMS2S/' , ' https://www.cnn.com/election/2020' , ' https://paperswithcode.com/sota' ]
6362shortener.shorten_urls(long_urls)
64- [' https://j.mp/3jx2gft' , ' https://j.mp/31IQt7D' , ' https://j.mp/2YNKi01' ]
65- vanity_shortener.shorten_urls(long_urls)
66- [' https://amzn.to/3jx2gft' , ' https://cnn.it/31IQt7D' , ' https://j.mp/2YNKi01' ]
63+ [' https://amzn.to/2HcWFgV' , ' https://cnn.it/3ofdpVp' , ' https://j.mp/2IHwQ8P' ]
6764
6865# Shorten to dict
6966long_urls = [' https://news.google.com' , ' https://yahoo.com/' ]
7067shortener.shorten_urls_to_dict(long_urls)
71- {' https://news.google.com' : ' https://j.mp/2TzvYnq ' , ' https://yahoo.com/' : ' https://j.mp/2TCihE4 ' }
68+ {' https://news.google.com' : ' https://j.mp/31t9qL2 ' , ' https://yahoo.com/' : ' https://yhoo.it/3ondJS2 ' }
7269
7370# Normalize diverse preexisting Bitly links
7471urls = [' http://j.mp/2Bo2LVf' , ' http://bit.ly/2BombJQ' , ' https://cnn.it/2Ggb2ih' , ' https://j.mp/websniffer' ]
7572shortener.shorten_urls(urls)
76- [' https://j.mp/2BtckCt' , ' https://j.mp/2BlS1qw' , ' https://j.mp/2TEVtUt' , ' https://j.mp/2BmjqbZ' ]
77- vanity_shortener.shorten_urls(urls)
78- [' https://j.mp/3b9UzJ3' , ' https://j.mp/31H7GhP' , ' https://cnn.it/2YPARxb' , ' https://j.mp/2EKXwDU' ]
73+ [' https://j.mp/37qFvH0' , ' https://j.mp/3obETLt' , ' https://cnn.it/2FMI6jc' , ' https://j.mp/37FmjFV' ]
7974
8075# Show usage for tokens pool (cached for an hour)
8176shortener.usage()
82770.4604 # Means that an average of 46% of the current calendar month's URL shortening quota has been used across all tokens.
8378
8479# Show cache info
8580shortener.cache_info
86- {' Shortener._shorten_url' : CacheInfo(hits = 0 , misses = 9 , maxsize = 256 , currsize = 9 )}
81+ {' Shortener._shorten_url' : CacheInfo(hits = 4 , misses = 10 , maxsize = 128 , currsize = 10 )}
8782```
8883
8984To obtain the fastest response, URLs must be shortened together in a batch as in the examples above.
0 commit comments