@@ -56,34 +56,29 @@ import bitlyshortener
56
56
# Setup
57
57
tokens_pool = [' 9fbe2864bb8872f5027c103321ff91be90aea687' , ' 0cbe3864bc8872f5027c103321ff91be30aea787' ] # Use your own.
58
58
shortener = 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.
60
59
61
60
# Shorten to list
62
61
long_urls = [' https://www.amazon.com/gp/product/B07LFJMS2S/' , ' https://www.cnn.com/election/2020' , ' https://paperswithcode.com/sota' ]
63
62
shortener.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' ]
67
64
68
65
# Shorten to dict
69
66
long_urls = [' https://news.google.com' , ' https://yahoo.com/' ]
70
67
shortener.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 ' }
72
69
73
70
# Normalize diverse preexisting Bitly links
74
71
urls = [' http://j.mp/2Bo2LVf' , ' http://bit.ly/2BombJQ' , ' https://cnn.it/2Ggb2ih' , ' https://j.mp/websniffer' ]
75
72
shortener.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' ]
79
74
80
75
# Show usage for tokens pool (cached for an hour)
81
76
shortener.usage()
82
77
0.4604 # Means that an average of 46% of the current calendar month's URL shortening quota has been used across all tokens.
83
78
84
79
# Show cache info
85
80
shortener.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 )}
87
82
```
88
83
89
84
To obtain the fastest response, URLs must be shortened together in a batch as in the examples above.
0 commit comments