Port to python3, fix ssl support

This commit is contained in:
mutantmonkey
2011-09-22 14:17:27 -04:00
parent 8d601d52bd
commit 50fe275870
41 changed files with 628 additions and 622 deletions

View File

@@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import re, math, time, urllib, locale, socket, struct, datetime
import re, math, time, urllib.request, urllib.parse, urllib.error, locale, socket, struct, datetime
from decimal import Decimal as dec
from tools import deprecated
@@ -203,9 +203,9 @@ def f_time(self, origin, match, args):
People = self.config.timezones
else: People = {}
if People.has_key(tz):
if tz in People:
tz = People[tz]
elif (not match.group(2)) and People.has_key(origin.nick):
elif (not match.group(2)) and origin.nick in People:
tz = People[origin.nick]
TZ = tz.upper()
@@ -218,7 +218,7 @@ def f_time(self, origin, match, args):
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 TimeZones.has_key(TZ):
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)
@@ -273,7 +273,7 @@ yi.priority = 'low'
def tock(phenny, input):
"""Shows the time from the USNO's atomic clock."""
u = urllib.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
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')
@@ -290,7 +290,7 @@ def npl(phenny, input):
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)
d -= dec(2208988800)
a, b = str(d).split('.')
f = '%Y-%m-%d %H:%M:%S'
result = datetime.datetime.fromtimestamp(d).strftime(f) + '.' + b[:6]
@@ -300,4 +300,4 @@ npl.commands = ['npl']
npl.priority = 'high'
if __name__ == '__main__':
print __doc__.strip()
print(__doc__.strip())