Tweaked plugins/time.py - more coming soon :)
This commit is contained in:
parent
10648e9bb2
commit
d39fdc51af
2 changed files with 9 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ gitflow
|
||||||
*.orig
|
*.orig
|
||||||
.project
|
.project
|
||||||
.pydevproject
|
.pydevproject
|
||||||
|
.geany
|
||||||
|
|
|
@ -191,6 +191,7 @@ TimeZones.update(TZ3)
|
||||||
|
|
||||||
r_local = re.compile(r'\([a-z]+_[A-Z]+\)')
|
r_local = re.compile(r'\([a-z]+_[A-Z]+\)')
|
||||||
|
|
||||||
|
# gets the time from a timezone (code from phenny)
|
||||||
def get_time(tz):
|
def get_time(tz):
|
||||||
TZ = tz.upper()
|
TZ = tz.upper()
|
||||||
|
|
||||||
|
@ -206,10 +207,10 @@ def get_time(tz):
|
||||||
timenow = time.gmtime(time.time() + offset)
|
timenow = time.gmtime(time.time() + offset)
|
||||||
msg = time.strftime("\x02%I:%M%p\x02 %A - \x02Time\x02 in \x02" + str(TZ), timenow)
|
msg = time.strftime("\x02%I:%M%p\x02 %A - \x02Time\x02 in \x02" + str(TZ), timenow)
|
||||||
return msg
|
return msg
|
||||||
#elif tz and tz[0] in ('+', '-') and 4 <= len(tz) <= 6:
|
elif tz and tz[0] in ('+', '-') and 4 <= len(tz) <= 6:
|
||||||
# timenow = time.gmtime(time.time() + (int(tz[:3]) * 3600))
|
timenow = time.gmtime(time.time() + (int(tz[:3]) * 3600))
|
||||||
# msg = time.strftime("4\x02%I:%M%p\x02 %A - \x02Time\x02 in \x02" + str(tz), timenow)
|
msg = time.strftime("\x02%I:%M%p\x02 %A - \x02Time\x02 in\x02 GMT" + str(tz), timenow)
|
||||||
# return msg
|
return msg
|
||||||
else:
|
else:
|
||||||
timenow = time.gmtime(time.time() + (int(tz) * 3600))
|
timenow = time.gmtime(time.time() + (int(tz) * 3600))
|
||||||
msg = time.strftime("\x02%I:%M%p\x02 %A - \x02Time\x02 in\x02 GMT " + str(tz), timenow)
|
msg = time.strftime("\x02%I:%M%p\x02 %A - \x02Time\x02 in\x02 GMT " + str(tz), timenow)
|
||||||
|
@ -219,7 +220,6 @@ def get_time(tz):
|
||||||
def timecommand(inp, say = None):
|
def timecommand(inp, say = None):
|
||||||
".time <area> -- Gets the time in <area>"
|
".time <area> -- Gets the time in <area>"
|
||||||
|
|
||||||
white_re = re.compile(r'\s+')
|
|
||||||
tags_re = re.compile(r'<[^<]*?>')
|
tags_re = re.compile(r'<[^<]*?>')
|
||||||
|
|
||||||
page = http.get('http://www.google.com/search', q = "time in " + inp)
|
page = http.get('http://www.google.com/search', q = "time in " + inp)
|
||||||
|
@ -230,18 +230,11 @@ def timecommand(inp, say = None):
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
output = response.renderContents()
|
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 = tags_re.sub('\x02', output.strip())
|
||||||
|
|
||||||
output = output.decode('utf-8', 'ignore')
|
|
||||||
return output
|
return output
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
output = get_time(inp)
|
return get_time(inp)
|
||||||
return output
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return "Could not get the time for " + inp + "!"
|
return "Could not get the time for " + inp + "!"
|
||||||
|
|
Reference in a new issue