summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSean B. Palmer <sbp@aldebaran.local>2010-04-03 11:08:03 +0100
committerSean B. Palmer <sbp@aldebaran.local>2010-04-03 11:08:03 +0100
commitb4c7019d53eea1e642579fa87f5b0b0431e4aa6a (patch)
tree27e3bfb355e78c953dec59eee54f6ee18d6f7a99 /modules
parentc5b234578ef0a1231e99153eb7b0bb9e11255742 (diff)
downloadbot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.tar.gz
bot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.tar.bz2
bot-b4c7019d53eea1e642579fa87f5b0b0431e4aa6a.zip
Fixed the Wikipedia module's search capability.
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/clock.py22
-rwxr-xr-xmodules/head.py6
-rwxr-xr-xmodules/oblique.py3
-rwxr-xr-xmodules/wikipedia.py4
4 files changed, 30 insertions, 5 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()
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)<li>(.*?)</li>')
r_tag = re.compile(r'<[^>]+>')
diff --git a/modules/wikipedia.py b/modules/wikipedia.py
index e1c059c..0542067 100755
--- a/modules/wikipedia.py
+++ b/modules/wikipedia.py
@@ -126,8 +126,8 @@ def wikipedia(term, last=False):
words.pop()
sentence = ' '.join(words) + ' [...]'
- if ((sentence == 'Wikipedia does not have an article with this exact name.')
- or (sentence == 'Wikipedia does not have a page with this exact name.')):
+ if (('using the Article Wizard if you wish' in sentence)
+ or ('or add a request for it' in sentence)):
if not last:
term = search(term)
return wikipedia(term, last=True)