|
Revision 35, 0.5 kB
(checked in by simon, 2 years ago)
|
- Check the link before potting.
|
- Property svn:executable set to
*
|
| Line | |
|---|
| 1 |
#!/usr/bin/env python |
|---|
| 2 |
|
|---|
| 3 |
import urllib |
|---|
| 4 |
import re |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
def check_link(url): |
|---|
| 8 |
# Get the URL to check it "works" |
|---|
| 9 |
urllib.urlopen(url) |
|---|
| 10 |
|
|---|
| 11 |
pot_re = re.compile(r'Your quick url is <a href="(http://linkpot.net/.*?)"') |
|---|
| 12 |
|
|---|
| 13 |
def linkpot(url): |
|---|
| 14 |
post_data = urllib.urlencode({'url': url}) |
|---|
| 15 |
res = urllib.urlopen('http://linkpot.net/add/', post_data).read() |
|---|
| 16 |
pot = pot_re.search(res).group(1) |
|---|
| 17 |
return pot |
|---|
| 18 |
|
|---|
| 19 |
if __name__ == '__main__': |
|---|
| 20 |
import sys |
|---|
| 21 |
try: |
|---|
| 22 |
check_link(sys.argv[1]) |
|---|
| 23 |
print linkpot(sys.argv[1]) |
|---|
| 24 |
except Exception: |
|---|
| 25 |
sys.exit(1) |
|---|