pep8 tweaks

This commit is contained in:
Luke Rogers 2012-03-13 07:13:32 +13:00
parent a1eb155b14
commit 923e829068
4 changed files with 18 additions and 11 deletions

View file

@ -3,8 +3,9 @@ import re
from util import hook, http, misc
from BeautifulSoup import BeautifulSoup
@hook.command("calc")
@hook.command("math")
@hook.command
def calc(inp):
".calc <term> -- Calculate <term> with Google Calc."
@ -14,7 +15,7 @@ def calc(inp):
soup = BeautifulSoup(page)
response = soup.find('h2', {'class' : 'r'})
response = soup.find('h2', {'class': 'r'})
if response is None:
return "Could not calculate " + inp

View file

@ -1,9 +1,11 @@
from util import hook
def find_location(ip, api):
import string
import urllib
response = urllib.urlopen("http://api.ipinfodb.com/v3/ip-city/?key="+api+"&ip="+ip).read()
response = urllib.urlopen("http://api.ipinfodb.com/v3/ip-city/?key=" \
+ api + "&ip=" + ip).read()
response = response.split(";")
give = {}
give["country"] = response[4].title()
@ -13,6 +15,7 @@ def find_location(ip, api):
give["timezone"] = response[10].title()
return give
def timezone(ip):
time = find_location(ip)["timezone"]
time = time.replace(":", ".")

View file

@ -2,6 +2,7 @@
from util import hook
import urllib2
@hook.command
def gitio(inp):
".gitio <url> [code] -- Shorten Github URLs with git.io. [code] is a optional custom short code."
@ -13,13 +14,14 @@ def gitio(inp):
except:
code = None
# if the first 8 chars of "url" are not "https://" then append "https://" to the url, also convert "http://" to "https://"
# if the first 8 chars of "url" are not "https://" then append
# "https://" to the url, also convert "http://" to "https://"
if url[:8] != "https://":
if url[:7] != "http://":
url = "https://" + url
else:
url = "https://" + url[7:]
url='url='+str(url)
url = 'url=' + str(url)
if code:
url = url + '&code=' + str(code)
req = urllib2.Request(url='http://git.io', data=url)
@ -31,7 +33,8 @@ def gitio(inp):
return "Failed to get URL!"
urlinfo = str(f.info())
# loop over the rows in urlinfo and pick out location and status (this is pretty odd code, but urllib2.Request is weird)
# loop over the rows in urlinfo and pick out location and
# status (this is pretty odd code, but urllib2.Request is weird)
for row in urlinfo.split("\n"):
if row.find("Status") != -1:
status = row

View file

@ -15,11 +15,11 @@ def gis(inp):
parsed = api_get('images', inp)
if not 200 <= parsed['responseStatus'] < 300:
raise IOError('error searching for images: %d: %s' % (
raise IOError('error searching for images: %d: %s' % ( \
parsed['responseStatus'], ''))
if not parsed['responseData']['results']:
return 'no images found'
return random.choice(parsed['responseData']['results'][:10])\
return random.choice(parsed['responseData']['results'][:10]) \
['unescapedUrl'] # squares is dumb