Moved haste() to util/web

This commit is contained in:
Luke Rogers 2012-09-02 23:48:47 +12:00
parent 23dde386d0
commit c44b1dcd6a
2 changed files with 11 additions and 10 deletions

View file

@ -1,6 +1,7 @@
""" web.py - handy functions for web services """
import http, urlnorm
import json, urllib2
from urllib import urlencode
@ -28,4 +29,11 @@ def isgd(url):
""" shortens a URL with the is.gd PAI """
url = urlnorm.normalize(url.encode('utf-8'))
params = urlencode({'format': 'simple', 'url': url})
return http.get("http://is.gd/create.php?%s" % params)
return http.get("http://is.gd/create.php?%s" % params)
def haste(data):
URL = "http://paste.dmptr.com"
request = urllib2.Request(URL + "/documents", data)
response = urllib2.urlopen(request)
return("%s/%s" % (URL, json.loads(response.read())['key']))