Skip to content

Instantly share code, notes, and snippets.

@badp
Created June 24, 2010 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badp/451227 to your computer and use it in GitHub Desktop.
Save badp/451227 to your computer and use it in GitHub Desktop.
Quick and dirty is.gd interface in Python
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()
@systempuntoout
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment