This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/util/web.py

22 lines
608 B
Python
Raw Normal View History

2012-04-21 05:55:52 +02:00
""" web.py - handy functions for web services """
import http, urlnorm
import json, urllib
2012-04-21 05:55:52 +02:00
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'))
2012-09-04 21:52:03 +02:00
params = urllib.urlencode({'format': 'simple', 'url': url})
2012-09-02 13:48:47 +02:00
return http.get("http://is.gd/create.php?%s" % params)
def haste(text):
""" pastes text to a hastebin server """
page = http.get(paste_url + "/documents", post_data=text)
data = json.loads(page)
2012-09-04 21:52:03 +02:00
return("%s/%s.txt" % (paste_url, data['key']))