This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/util/web.py
2012-09-05 07:52:03 +12:00

22 lines
668 B
Python
Executable file

""" web.py - handy functions for web services """
import http, urlnorm
import json, urllib, urllib2
short_url = "http://is.gd/create.php"
paste_url = "http://paste.dmptr.com"
def isgd(url):
""" shortens a URL with the is.gd PAI """
url = urlnorm.normalize(url.encode('utf-8'))
params = urllib.urlencode({'format': 'simple', 'url': url})
return http.get("http://is.gd/create.php?%s" % params)
def haste(text):
""" pastes text to a hastebin server """
request = urllib2.Request(paste_url + "/documents", text)
response = urllib2.urlopen(request)
data = json.loads(response.read())
return("%s/%s.txt" % (paste_url, data['key']))