renamed gtime.py before working on it
This commit is contained in:
parent
6f02860279
commit
dd85311044
1 changed files with 0 additions and 0 deletions
33
plugins/time.py
Executable file
33
plugins/time.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
import re
|
||||
|
||||
from util import hook, http
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
|
||||
|
||||
@hook.command("time")
|
||||
def clock(inp, say=None):
|
||||
".time <area> -- Gets the time in <area>"
|
||||
|
||||
white_re = re.compile(r'\s+')
|
||||
tags_re = re.compile(r'<[^<]*?>')
|
||||
|
||||
page = http.get('http://www.google.com/search', q="time in " + inp)
|
||||
|
||||
soup = BeautifulSoup(page)
|
||||
|
||||
response = soup.find('td', {'style' : 'font-size:medium'})
|
||||
|
||||
if response is None:
|
||||
return "Could not get the time for " + inp + "!"
|
||||
|
||||
output = response.renderContents()
|
||||
|
||||
output = ' '.join(output.splitlines())
|
||||
output = output.replace("\xa0", ",")
|
||||
|
||||
output = white_re.sub(' ', output.strip())
|
||||
output = tags_re.sub('\x02', output.strip())
|
||||
|
||||
output = output.decode('utf-8', 'ignore')
|
||||
|
||||
return output
|
Reference in a new issue