Created
June 24, 2010 09:32
-
-
Save badp/451227 to your computer and use it in GitHub Desktop.
Quick and dirty is.gd interface in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
def isgd(url): | |
request_dict = {"longurl": url} | |
request = urllib.urlencode(request_dict) | |
result = urllib.urlopen("http://is.gd/api.php?" + request) | |
if result.getcode() == 500: | |
raise ValueError(result.read()) | |
else: | |
return result.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ciao :).. e' chiaro che la fuori ci siano diversi servizi che puoi invocare per ottenere lo shorten url.
Purtroppo pero' App Engine taglia la connessione dando un fantastico error 500 se dopo 30 secondi non onori la request con una response; e questi 30 secondi risicati li uso già per chiamare le Stack Exchange API ed ottenere i dettagli della Question.
Figurati, mi capita già di beccarlo su Question che hanno centinaia di commenti e risposte (http://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion); se dovessi introdurre altro delay per chiamare http://is.gd sarebbe la fine.
Non ti rimane altro che, dare gli esami che starai sicuramente preparando, e buttarti su StackPrinter implementando tutto quanto :).
Hai votato l'applicazione :)?? Se hai amici, falli votare!
Ci sentiamo!
Michele