diff options
author | Sean B. Palmer <sbp@aldebaran.local> | 2010-04-03 11:08:03 +0100 |
---|---|---|
committer | Sean B. Palmer <sbp@aldebaran.local> | 2010-04-03 11:08:03 +0100 |
commit | b4c7019d53eea1e642579fa87f5b0b0431e4aa6a (patch) | |
tree | 27e3bfb355e78c953dec59eee54f6ee18d6f7a99 /modules/clock.py | |
parent | c5b234578ef0a1231e99153eb7b0bb9e11255742 (diff) | |
download | bot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.tar.gz bot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.tar.bz2 bot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.zip |
Fixed the Wikipedia module's search capability.
Diffstat (limited to 'modules/clock.py')
-rwxr-xr-x | modules/clock.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/modules/clock.py b/modules/clock.py index b8c659b..f848423 100755 --- a/modules/clock.py +++ b/modules/clock.py @@ -7,7 +7,8 @@ Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ """ -import re, math, time, urllib, locale +import re, math, time, urllib, locale, socket, struct, datetime +from decimal import Decimal as dec from tools import deprecated TimeZones = {'KST': 9, 'CADT': 10.5, 'EETDST': 3, 'MESZ': 2, 'WADT': 9, @@ -277,5 +278,24 @@ def tock(phenny, input): 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(2208988800L) + 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() |