module formatting tweaks; tabs -> spaces and more

This commit is contained in:
mutantmonkey
2012-01-03 14:09:34 -05:00
parent 733d3fd39e
commit 56f116732d
32 changed files with 1307 additions and 1434 deletions

View File

@@ -12,20 +12,20 @@ from decimal import Decimal as dec
from tools import deprecated
TimeZones = {'KST': 9, 'CADT': 10.5, 'EETDST': 3, 'MESZ': 2, 'WADT': 9,
'EET': 2, 'MST': -7, 'WAST': 8, 'IST': 5.5, 'B': 2,
'MSK': 3, 'X': -11, 'MSD': 4, 'CETDST': 2, 'AST': -4,
'HKT': 8, 'JST': 9, 'CAST': 9.5, 'CET': 1, 'CEST': 2,
'EEST': 3, 'EAST': 10, 'METDST': 2, 'MDT': -6, 'A': 1,
'UTC': 0, 'ADT': -3, 'EST': -5, 'E': 5, 'D': 4, 'G': 7,
'F': 6, 'I': 9, 'H': 8, 'K': 10, 'PDT': -7, 'M': 12,
'L': 11, 'O': -2, 'MEST': 2, 'Q': -4, 'P': -3, 'S': -6,
'R': -5, 'U': -8, 'T': -7, 'W': -10, 'WET': 0, 'Y': -12,
'CST': -6, 'EADT': 11, 'Z': 0, 'GMT': 0, 'WETDST': 1,
'C': 3, 'WEST': 1, 'CDT': -5, 'MET': 1, 'N': -1, 'V': -9,
'EDT': -4, 'UT': 0, 'PST': -8, 'MEZ': 1, 'BST': 1,
'ACS': 9.5, 'ATL': -4, 'ALA': -9, 'HAW': -10, 'AKDT': -8,
'AKST': -9,
'BDST': 2}
'EET': 2, 'MST': -7, 'WAST': 8, 'IST': 5.5, 'B': 2,
'MSK': 3, 'X': -11, 'MSD': 4, 'CETDST': 2, 'AST': -4,
'HKT': 8, 'JST': 9, 'CAST': 9.5, 'CET': 1, 'CEST': 2,
'EEST': 3, 'EAST': 10, 'METDST': 2, 'MDT': -6, 'A': 1,
'UTC': 0, 'ADT': -3, 'EST': -5, 'E': 5, 'D': 4, 'G': 7,
'F': 6, 'I': 9, 'H': 8, 'K': 10, 'PDT': -7, 'M': 12,
'L': 11, 'O': -2, 'MEST': 2, 'Q': -4, 'P': -3, 'S': -6,
'R': -5, 'U': -8, 'T': -7, 'W': -10, 'WET': 0, 'Y': -12,
'CST': -6, 'EADT': 11, 'Z': 0, 'GMT': 0, 'WETDST': 1,
'C': 3, 'WEST': 1, 'CDT': -5, 'MET': 1, 'N': -1, 'V': -9,
'EDT': -4, 'UT': 0, 'PST': -8, 'MEZ': 1, 'BST': 1,
'ACS': 9.5, 'ATL': -4, 'ALA': -9, 'HAW': -10, 'AKDT': -8,
'AKST': -9,
'BDST': 2}
TZ1 = {
'NDT': -2.5,
@@ -183,8 +183,8 @@ TZ2 = {
}
TZ3 = {
'AEST': 10,
'AEDT': 11
'AEST': 10,
'AEDT': 11
}
# TimeZones.update(TZ2) # do these have to be negated?
@@ -195,109 +195,109 @@ r_local = re.compile(r'\([a-z]+_[A-Z]+\)')
@deprecated
def f_time(self, origin, match, args):
"""Returns the current time."""
tz = match.group(2) or 'GMT'
"""Returns the current time."""
tz = match.group(2) or 'GMT'
# Personal time zones, because they're rad
if hasattr(self.config, 'timezones'):
People = self.config.timezones
else: People = {}
# Personal time zones, because they're rad
if hasattr(self.config, 'timezones'):
People = self.config.timezones
else: People = {}
if tz in People:
tz = People[tz]
elif (not match.group(2)) and origin.nick in People:
tz = People[origin.nick]
if tz in People:
tz = People[tz]
elif (not match.group(2)) and origin.nick in People:
tz = People[origin.nick]
TZ = tz.upper()
if len(tz) > 30: return
TZ = tz.upper()
if len(tz) > 30: return
if (TZ == 'UTC') or (TZ == 'Z'):
msg = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
self.msg(origin.sender, msg)
elif r_local.match(tz): # thanks to Mark Shoulsdon (clsn)
locale.setlocale(locale.LC_TIME, (tz[1:-1], 'UTF-8'))
msg = time.strftime("%A, %d %B %Y %H:%M:%SZ", time.gmtime())
self.msg(origin.sender, msg)
elif TZ in TimeZones:
offset = TimeZones[TZ] * 3600
timenow = time.gmtime(time.time() + offset)
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(TZ), timenow)
self.msg(origin.sender, msg)
elif tz and tz[0] in ('+', '-') and 4 <= len(tz) <= 6:
timenow = time.gmtime(time.time() + (int(tz[:3]) * 3600))
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow)
self.msg(origin.sender, msg)
else:
try: t = float(tz)
except ValueError:
import os, re, subprocess
r_tz = re.compile(r'^[A-Za-z]+(?:/[A-Za-z_]+)*$')
if r_tz.match(tz) and os.path.isfile('/usr/share/zoneinfo/' + tz):
cmd, PIPE = 'TZ=%s date' % tz, subprocess.PIPE
proc = subprocess.Popen(cmd, shell=True, stdout=PIPE)
self.msg(origin.sender, proc.communicate()[0])
else:
error = "Sorry, I don't know about the '%s' timezone." % tz
self.msg(origin.sender, origin.nick + ': ' + error)
else:
timenow = time.gmtime(time.time() + (t * 3600))
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow)
self.msg(origin.sender, msg)
if (TZ == 'UTC') or (TZ == 'Z'):
msg = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
self.msg(origin.sender, msg)
elif r_local.match(tz): # thanks to Mark Shoulsdon (clsn)
locale.setlocale(locale.LC_TIME, (tz[1:-1], 'UTF-8'))
msg = time.strftime("%A, %d %B %Y %H:%M:%SZ", time.gmtime())
self.msg(origin.sender, msg)
elif TZ in TimeZones:
offset = TimeZones[TZ] * 3600
timenow = time.gmtime(time.time() + offset)
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(TZ), timenow)
self.msg(origin.sender, msg)
elif tz and tz[0] in ('+', '-') and 4 <= len(tz) <= 6:
timenow = time.gmtime(time.time() + (int(tz[:3]) * 3600))
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow)
self.msg(origin.sender, msg)
else:
try: t = float(tz)
except ValueError:
import os, re, subprocess
r_tz = re.compile(r'^[A-Za-z]+(?:/[A-Za-z_]+)*$')
if r_tz.match(tz) and os.path.isfile('/usr/share/zoneinfo/' + tz):
cmd, PIPE = 'TZ=%s date' % tz, subprocess.PIPE
proc = subprocess.Popen(cmd, shell=True, stdout=PIPE)
self.msg(origin.sender, proc.communicate()[0])
else:
error = "Sorry, I don't know about the '%s' timezone." % tz
self.msg(origin.sender, origin.nick + ': ' + error)
else:
timenow = time.gmtime(time.time() + (t * 3600))
msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow)
self.msg(origin.sender, msg)
f_time.commands = ['t']
f_time.name = 't'
f_time.example = '.t UTC'
def beats(phenny, input):
"""Shows the internet time in Swatch beats."""
beats = ((time.time() + 3600) % 86400) / 86.4
beats = int(math.floor(beats))
phenny.say('@%03i' % beats)
"""Shows the internet time in Swatch beats."""
beats = ((time.time() + 3600) % 86400) / 86.4
beats = int(math.floor(beats))
phenny.say('@%03i' % beats)
beats.commands = ['beats']
beats.priority = 'low'
def divide(input, by):
return (input / by), (input % by)
return (input / by), (input % by)
def yi(phenny, input):
"""Shows whether it is currently yi or not."""
quadraels, remainder = divide(int(time.time()), 1753200)
raels = quadraels * 4
extraraels, remainder = divide(remainder, 432000)
if extraraels == 4:
return phenny.say('Yes! PARTAI!')
elif extraraels == 3:
return phenny.say('Soon...')
else: phenny.say('Not yet...')
"""Shows whether it is currently yi or not."""
quadraels, remainder = divide(int(time.time()), 1753200)
raels = quadraels * 4
extraraels, remainder = divide(remainder, 432000)
if extraraels == 4:
return phenny.say('Yes! PARTAI!')
elif extraraels == 3:
return phenny.say('Soon...')
else: phenny.say('Not yet...')
yi.commands = ['yi']
yi.priority = 'low'
def tock(phenny, input):
"""Shows the time from the USNO's atomic clock."""
u = urllib.request.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
info = u.info()
u.close()
phenny.say('"' + info['Date'] + '" - tycho.usno.navy.mil')
"""Shows the time from the USNO's atomic clock."""
u = urllib.request.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
info = u.info()
u.close()
phenny.say('"' + info['Date'] + '" - tycho.usno.navy.mil')
tock.commands = ['tock']
tock.priority = 'high'
def npl(phenny, input):
"""Shows the time from NPL's SNTP server."""
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.sendto('\x1b' + 47 * '\0', ('ntp1.npl.co.uk', 123))
data, address = client.recvfrom(1024)
if data:
buf = struct.unpack('B' * 48, data)
d = dec('0.0')
for i in range(8):
d += dec(buf[32 + i]) * dec(str(math.pow(2, (3 - i) * 8)))
d -= dec(2208988800)
a, b = str(d).split('.')
f = '%Y-%m-%d %H:%M:%S'
result = datetime.datetime.fromtimestamp(d).strftime(f) + '.' + b[:6]
phenny.say(result + ' - ntp1.npl.co.uk')
else: phenny.say('No data received, sorry')
"""Shows the time from NPL's SNTP server."""
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.sendto('\x1b' + 47 * '\0', ('ntp1.npl.co.uk', 123))
data, address = client.recvfrom(1024)
if data:
buf = struct.unpack('B' * 48, data)
d = dec('0.0')
for i in range(8):
d += dec(buf[32 + i]) * dec(str(math.pow(2, (3 - i) * 8)))
d -= dec(2208988800)
a, b = str(d).split('.')
f = '%Y-%m-%d %H:%M:%S'
result = datetime.datetime.fromtimestamp(d).strftime(f) + '.' + b[:6]
phenny.say(result + ' - ntp1.npl.co.uk')
else: phenny.say('No data received, sorry')
npl.commands = ['npl']
npl.priority = 'high'
if __name__ == '__main__':
print(__doc__.strip())
print(__doc__.strip())