forked from sumana2001/Pybull
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlShort.py
More file actions
19 lines (16 loc) · 760 Bytes
/
urlShort.py
File metadata and controls
19 lines (16 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from __future__ import with_statement
import contextlib
from urllib.parse import urlencode
from urllib import urlencode
from urllib.request import urlopen
from urllib2 import urlopen
import sys
def short_url(url):
request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url}))
with contextlib.closing(urlopen(request_url)) as response:
return response.read().decode('utf-8 ')
def main():
for url in map(short_url, sys.argv[1:]):
print(url)
if __name__ == '__main__':
main()