Python 3 Start

This commit is contained in:
Luke Rogers 2014-03-06 11:45:00 +13:00
parent 9f029c8ceb
commit 141fe8d80c
67 changed files with 264 additions and 274 deletions

View file

@ -1,16 +1,13 @@
""" web.py - handy functions for web services """
import http
import urlnorm
from . import http
from . import urlnorm
import json
import urllib
import yql
import urllib.request, urllib.parse, urllib.error
short_url = "http://is.gd/create.php"
paste_url = "http://hastebin.com"
yql_env = "http://datatables.org/alltables.env"
YQL = yql.Public()
class ShortenError(Exception):
@ -25,7 +22,7 @@ class ShortenError(Exception):
def isgd(url):
""" shortens a URL with the is.gd API """
url = urlnorm.normalize(url.encode('utf-8'), assume_scheme='http')
params = urllib.urlencode({'format': 'json', 'url': url})
params = urllib.parse.urlencode({'format': 'json', 'url': url})
request = http.get_json("http://is.gd/create.php?%s" % params)
if "errorcode" in request:
@ -46,9 +43,4 @@ def haste(text, ext='txt'):
""" pastes text to a hastebin server """
page = http.get(paste_url + "/documents", post_data=text)
data = json.loads(page)
return ("%s/%s.%s" % (paste_url, data['key'], ext))
def query(query, params={}):
""" runs a YQL query and returns the results """
return YQL.execute(query, params, env=yql_env)
return "{}/{}.{}".format(paste_url, data['key'], ext)