Skip to content

Commit 2324689

Browse files
committed
Implemented chilp.it service.
1 parent 98ce28a commit 2324689

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Supported URL shortening services for shrinking long urls:
2222
buk.me
2323
fon.gs
2424
fwd4.me
25+
chilp.it
2526

2627
Shorty can expand any url service by getting the redirect
2728
location by requesting the tiny url.

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
+ burnurl.com
2-
+ chilp.it

shorty.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,42 @@ def shrink(self, bigurl):
465465

466466
fwd4me = Fwd4me()
467467

468+
# chilp.it
469+
class Chilpit(Service):
470+
471+
def shrink(self, bigurl):
472+
resp = request('http://chilp.it/api.php', {'url': bigurl})
473+
url = resp.read()
474+
if url.startswith('http://'):
475+
return url
476+
else:
477+
raise ShortyError(url)
478+
479+
def expand(self, tinyurl):
480+
turl = urlparse(tinyurl)
481+
if turl.netloc.lstrip('www.') != 'chilp.it':
482+
raise ShortyError('Not a chilp.it url')
483+
resp = request('http://p.chilp.it/api.php?' + turl.path.strip('/'))
484+
url = resp.read()
485+
if url.startswith('http://'):
486+
return url
487+
else:
488+
raise ShortyError(url)
489+
490+
# get click stats of the tinyurl
491+
def stats(self, tinyurl):
492+
turl = urlparse(tinyurl)
493+
if turl.netloc.lstrip('www.') != 'chilp.it':
494+
raise ShortyError('Not a chilp.it url')
495+
resp = request('http://s.chilp.it/api.php?' + turl.query)
496+
hit_count = resp.read()
497+
try:
498+
return int(hit_count)
499+
except:
500+
raise ShortyError('Url not found or invalid')
501+
502+
chilpit = Chilpit()
503+
468504
"""Mapping of domain to service class"""
469505
services = {
470506
'sandbox': sandbox,
@@ -479,7 +515,8 @@ def shrink(self, bigurl):
479515
'a.gd': agd,
480516
'buk.me': bukme,
481517
'fon.gs': fongs,
482-
'fwd4.me': fwd4me
518+
'fwd4.me': fwd4me,
519+
'chilp.it': chilpit
483520
}
484521

485522
"""

0 commit comments

Comments
 (0)