Fixed the Wikipedia module's search capability.
parent
c5b234578e
commit
b4c7019d53
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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'<[^>]+>')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue