Skip to content

Commit

Permalink
A new scheduling command and some improvements to gc
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp committed Mar 15, 2013
1 parent 7752b56 commit a546977
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 17 deletions.
4 changes: 2 additions & 2 deletions modules/etymology.py
Expand Up @@ -84,7 +84,7 @@ def etymology(word):
sentence = ' '.join(words) + ' [...]'

sentence = '"' + sentence.replace('"', "'") + '"'
return sentence + ' - etymonline.com'
return sentence + ' - ' + ('http://etymonline.com/index.php?term=%s' % web.urllib.quote(word))

@deprecated
def f_etymology(self, origin, match, args):
Expand All @@ -102,7 +102,7 @@ def f_etymology(self, origin, match, args):
self.msg(origin.sender, result)
else:
uri = etysearch % word
msg = 'Can\'t find the etymology for "%s". Try %s' % (word, uri)
msg = 'Can\'t find the etymology for "%s". Try %s' % (word, ('http://etymonline.com/index.php?term=%s' % web.urllib.quote(word)))
self.msg(origin.sender, msg)
# @@ Cf. http://swhack.com/logs/2006-01-04#T01-50-22
f_etymology.rule = (['ety'], r"(.+?)$")
Expand Down
57 changes: 57 additions & 0 deletions modules/remind.py
Expand Up @@ -36,7 +36,10 @@ def dump_database(name, data):

def setup(phenny):
phenny.rfn = filename(phenny)

# phenny.sending.acquire()
phenny.rdb = load_database(phenny.rfn)
# phenny.sending.release()

def monitor(phenny):
time.sleep(5)
Expand All @@ -51,7 +54,10 @@ def monitor(phenny):
phenny.msg(channel, nick + ': ' + message)
else: phenny.msg(channel, nick + '!')
del phenny.rdb[oldtime]

# phenny.sending.acquire()
dump_database(phenny.rfn, phenny.rdb)
# phenny.sending.release()
time.sleep(2.5)

targs = (phenny,)
Expand Down Expand Up @@ -132,5 +138,56 @@ def remind(phenny, input):
else: phenny.reply('Okay, will remind in %s secs' % duration)
remind.commands = ['in']

r_time = re.compile(r'^([0-9]{2}[:.][0-9]{2})')
r_zone = re.compile(r'( ?([A-Za-z]+|[+-]\d\d?))')

import calendar
from clock import TimeZones

def at(phenny, input):
bytes = input[4:]

m = r_time.match(bytes)
if not m:
return phenny.reply("Sorry, didn't understand the time spec.")
t = m.group(1).replace('.', ':')
bytes = bytes[len(t):]

m = r_zone.match(bytes)
if not m:
return phenny.reply("Sorry, didn't understand the zone spec.")
z = m.group(2)
bytes = bytes[len(m.group(1)):].strip().encode("utf-8")

if z.startswith('+') or z.startswith('-'):
tz = int(z)

if TimeZones.has_key(z):
tz = TimeZones[z]
else: return phenny.reply("Sorry, didn't understand the time zone.")

d = time.strftime("%Y-%m-%d", time.gmtime())
d = time.strptime(("%s %s" % (d, t)).encode("utf-8"), "%Y-%m-%d %H:%M")

d = int(calendar.timegm(d) - (3600 * tz))
duration = int((d - time.time()) / 60)

if duration < 1:
return phenny.reply("Sorry, that date is this minute or in the past. And only times in the same day are supported!")

# phenny.say("%s %s %s" % (t, tz, d))

reminder = (input.sender, input.nick, bytes)
# phenny.say(str((d, reminder)))
try: phenny.rdb[d].append(reminder)
except KeyError: phenny.rdb[d] = [reminder]

phenny.sending.acquire()
dump_database(phenny.rfn, phenny.rdb)
phenny.sending.release()

phenny.reply("Reminding at %s %s - in %s minute(s)" % (t, z, duration))
at.commands = ['at']

if __name__ == '__main__':
print __doc__.strip()
32 changes: 28 additions & 4 deletions modules/search.py
Expand Up @@ -204,14 +204,34 @@ def suggest(phenny, input):
def new_gc(query):
uri = 'https://www.google.com/search?hl=en&q='
uri = uri + web.urllib.quote(query).replace('+', '%2B')
if '"' in query: uri += '&tbs=li:1'
# if '"' in query: uri += '&tbs=li:1'
bytes = web.get(uri)
if "did not match any documents" in bytes:
return "0"
for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes):
return result
return None

def newest_gc(query):
uri = 'https://www.google.com/search?hl=en&q='
uri = uri + web.urllib.quote(query).replace('+', '%2B')
bytes = web.get(uri + '&tbs=li:1')
if "did not match any documents" in bytes:
return "0"
for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes):
return result
return None

def newerest_gc(query):
uri = 'https://www.google.com/search?hl=en&q='
uri = uri + web.urllib.quote(query).replace('+', '%2B')
bytes = web.get(uri + '&prmd=imvns&start=950')
if "did not match any documents" in bytes:
return "0"
for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes):
return result
return None

def ngc(phenny, input):
if not input.group(2):
return phenny.reply("No query term.")
Expand All @@ -229,9 +249,13 @@ def gc(phenny, input):
if not input.group(2):
return phenny.reply("No query term.")
query = input.group(2).encode('utf-8')
old = old_gc(query) or "?"
new = new_gc(query) or "?"
phenny.say(query + ": " + old + " / " + new)
result = query + ": "
result += (old_gc(query) or "?") + " (api)"
result += ", " + (newerest_gc(query) or "?") + " (end)"
result += ", " + (new_gc(query) or "?") + " (site)"
if '"' in query:
result += ", " + (newest_gc(query) or "?") + " (verbatim)"
phenny.say(result)

gc.commands = ['gc']
gc.priority = 'high'
Expand Down
8 changes: 7 additions & 1 deletion modules/tell.py
Expand Up @@ -131,9 +131,13 @@ def message(phenny, input):
for remkey in remkeys:
if not remkey.endswith('*') or remkey.endswith(':'):
if tellee.lower() == remkey:
phenny.sending.acquire()
reminders.extend(getReminders(phenny, channel, remkey, tellee))
elif tellee.lower().startswith(remkey.rstrip('*:')):
phenny.sending.release()
elif tellee.lower().strip("0123456789_-[]`") == remkey.rstrip('*:'):
phenny.sending.acquire()
reminders.extend(getReminders(phenny, channel, remkey, tellee))
phenny.sending.release()

for line in reminders[:maximum]:
phenny.say(line)
Expand All @@ -144,7 +148,9 @@ def message(phenny, input):
phenny.msg(tellee, line)

if len(phenny.reminders.keys()) != remkeys:
phenny.sending.acquire()
dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell
phenny.sending.release()
message.rule = r'(.*)'
message.priority = 'low'

Expand Down
29 changes: 19 additions & 10 deletions modules/translate.py
Expand Up @@ -93,8 +93,8 @@ def langcode(p):
command = cmd
phrase = command

if (len(phrase) > 350) and (not input.admin):
return phenny.reply('Phrase must be under 350 characters.')
# if (len(phrase) > 350) and (not input.admin):
# return phenny.reply('Phrase must be under 350 characters.')

src, dest = args
if src != dest:
Expand All @@ -103,6 +103,7 @@ def langcode(p):
msg = msg.decode('utf-8')
if msg:
msg = web.decode(msg) # msg.replace('&#39;', "'")
if len(msg) > 450: msg = msg[:450] + '[...]'
msg = '"%s" (%s to %s, translate.google.com)' % (msg, src, dest)
else: msg = 'The %s to %s translation failed, sorry!' % (src, dest)

Expand All @@ -113,22 +114,30 @@ def langcode(p):
tr2.priority = 'low'

def mangle(phenny, input):
import time

phrase = input.group(2).encode('utf-8')
for lang in ['fr', 'de', 'es', 'it', 'ja']:
backup = phrase
phrase = translate(phrase, 'en', lang)
backup = phrase[:]
phrase, _lang = translate(phrase, 'en', lang)
phrase = phrase.encode("utf-8")

if not phrase:
phrase = backup
phrase = backup[:]
break
__import__('time').sleep(0.5)
time.sleep(0.25)

backup = phrase[:]
phrase, _lang = translate(phrase, lang, 'en')
phrase = phrase.encode("utf-8")

backup = phrase
phrase = translate(phrase, lang, 'en')
if not phrase:
phrase = backup
phrase = backup[:]
break
__import__('time').sleep(0.5)
time.sleep(0.25)

phrase = phrase.replace(' ,', ',').replace(' .', '.')
phrase = phrase.strip(' ,')
phenny.reply(phrase or 'ERRORS SRY')
mangle.commands = ['mangle']

Expand Down

0 comments on commit a546977

Please sign in to comment.