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() diff --git a/modules/head.py b/modules/head.py index 231ffdb..b6767ff 100755 --- a/modules/head.py +++ b/modules/head.py @@ -84,7 +84,11 @@ def f_title(self, origin, match, args): try: redirects = 0 while True: - req = urllib2.Request(uri, headers={'Accept':'text/html'}) + headers = { + 'Accept': 'text/html', + 'User-Agent': 'Mozilla/5.0 (Phenny)' + } + req = urllib2.Request(uri, headers=headers) u = urllib2.urlopen(req) info = u.info() u.close() diff --git a/modules/oblique.py b/modules/oblique.py index b4efa77..835862a 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -10,7 +10,8 @@ http://inamidst.com/phenny/ import re, urllib import web -definitions = 'http://code.google.com/p/phenny-ws/wiki/ServiceDefinitions' +# definitions = 'http://code.google.com/p/phenny-ws/wiki/ServiceDefinitions' +definitions = 'http://wiki.github.com/nslater/phenny-ws/' r_item = re.compile(r'(?i)