Commit b40ea545 authored by aLaserShark's avatar aLaserShark Committed by Svetlana Tkachenko
Browse files

fix google plugin and a few pep 8 violations



Signed-off-by: default avatargry <gryllida@gmail.com>
parent 4acb8298
......@@ -36,6 +36,6 @@ class Google(object):
if cmd == "google" or cmd == "g":
search = " ".join(args)
req = urllib.request.Request("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + urllib.parse.quote(search) + "&key=ABQIAAAA4B16PYoznYWgfVLfNDV4fxRsamdul3hUHNYXnxki2eGK76NS_RQ795CTZZ3l-TuRCO2d5eibFI1WZA")
data = str(urllib.request.urlopen(req).read())
data = urllib.request.urlopen(req).read().decode('utf-8')
splitdata = data.split("\"")
self.server.doMessage(channel, splitdata[31] + " - " + splitdata[11])
......@@ -42,12 +42,14 @@ class IsItUp(object):
url = args[0][8:]
else:
url = args[0]
code = "".join(x.decode('utf8') for x in urllib.request.urlopen("http://isitup.org/" + url + ".json").readlines())
code = "".join(x.decode('utf8') for x in urllib.request.urlopen("http://isitup.org/" +
url + ".json").readlines())
#code = code.decode('utf8')
print(code)
arr = json.loads(code)
arr['up'] = 'up' if arr['status_code'] == 1 else 'not up'
if arr['up'] == 'up':
self.server.doMessage(channel, user + ': %(domain)s:%(port)s is %(up)s. Got HTTP status code %(response_code)03d from %(response_ip)s in %(response_time)f ms.' % arr)
self.server.doMessage(channel, user + ': %(domain)s:%(port)s is %(up)s. Got HTTP status code %(response_'
'code)03d from %(response_ip)s in %(response_time)f ms.' % arr)
else:
self.server.doMessage(channel, user + ': %s is not up.' % arr['domain'])
......@@ -29,6 +29,7 @@ import re
@plugin
class yt(object):
"""`yt <id here>` to see a Youtube.com video information (title, ups, down, time, &c)."""
def __init__(self, server):
self.server = server
self.commands = ["yt"]
......@@ -37,25 +38,32 @@ class yt(object):
def handle_command(self, channel, user, cmd, args):
if cmd == "yt":
if len(args) < 1:
self.server.doMessage(channel, user + ": Return http://youtube.com video information by URL or id. Syntax: yt <video url or id>.")
self.server.doMessage(
channel, user + ": Return http://youtube.com video information by URL or id. "
"Syntax: yt <video url or id>.")
return
self.yt(channel, user, cmd, args)
def yt(self, channel, user, cmd, args):
request = re.sub(r"(?i)(?:https?://)?(?:www.)?(?:youtube.com/watch\?v=|youtu\.be/)([\w-]+)(?:[?&].*)?", r"\1", " ".join(args))
print("Request is `" + request + "`.")
sock = urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=json" % request)
data = sock.read().decode("utf-8")
sock.close()
try:
e = json.loads(data)["entry"]
except:
self.server.doMessage(channel, user + ": No data found.")
return
request = re.sub(r"(?i)(?:https?://)?(?:www.)?(?:youtube.com/watch\?v=|youtu\.be/)([\w-]+)(?:[?&].*)?", r"\1",
" ".join(args))
print("Request is `" + request + "`.")
sock = urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=json" % request)
data = sock.read().decode("utf-8")
sock.close()
try:
e = json.loads(data)["entry"]
h = int(e["media$group"]["yt$duration"]["seconds"]) // 3600
m = int(e["media$group"]["yt$duration"]["seconds"]) // 60 - h * 60
s = int(e["media$group"]["yt$duration"]["seconds"]) - h * 3600 - m * 60
self.server.doMessage(channel, user + ": " + "'{0}' by {1} ({2}:{3}:{4}) - Rating {5} - Favorite {6}/{7} - Date {8} - Likes {9}+ {10}- /{11} http://youtu.be/{12}".format(
except:
self.server.doMessage(channel, user + ": No data found.")
return
e = json.loads(data)["entry"]
h = int(e["media$group"]["yt$duration"]["seconds"]) // 3600
m = int(e["media$group"]["yt$duration"]["seconds"]) // 60 - h * 60
s = int(e["media$group"]["yt$duration"]["seconds"]) - h * 3600 - m * 60
# pycharm says that the following line is a big PEP 8 violation,
self.server.doMessage(channel, user + ": " + "'{0}' by {1} ({2}:{3}:{4}) - "
"Rating {5} - Favorite {6}/{7} - Date {8} - "
"Likes {9}+ {10}- /{11} http://youtu.be/{12}".format(
e["title"]["$t"],
e["author"][0]["name"]["$t"],
h, m, s,
......@@ -69,4 +77,4 @@ class yt(object):
int(e["yt$rating"]["numLikes"]) - int(json.loads(data)["entry"]["yt$rating"]["numDislikes"]),
request
)
)
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment