Skip to content

Commit 013d7a4

Browse files
kumannajoshthecoder
authored andcommitted
Add ur1.ca service.
This commit introduces ur1.ca support. Since ur1.ca is a simplistic service which doesn't offer many interfaces, the shortened URL is extracted by parsing the output HTML from the service. Suggestions for better implementation welcome. Signed-off-by: Joshua Roesslein <jroesslein@gmail.com>
1 parent 6f5574b commit 013d7a4

File tree

3 files changed

+465
-429
lines changed

3 files changed

+465
-429
lines changed

imports.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from random import randint
1010
import base64
1111
from getpass import getpass
12+
import re
1213

1314
try:
1415
import json

services/ur1ca.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Shorty
2+
## Copyright 2009 Kumar Appaiah
3+
## See LICENSE
4+
5+
## @url ur1.ca
6+
class Ur1ca(Service):
7+
8+
def shrink(self, bigurl):
9+
resp = request('http://ur1.ca/',
10+
post_data = urlencode({'longurl': bigurl, 'submit' : 'Make it an ur1!'}))
11+
returned_data = resp.read()
12+
matched_re = re.search('Your ur1 is: <a href="(http://ur1.ca/[^"]+)">\\1', returned_data)
13+
if matched_re:
14+
return matched_re.group(1)
15+
else:
16+
raise ShortyError('Failed to shrink url')
17+

0 commit comments

Comments
 (0)