Created
December 16, 2012 22:50
-
-
Save Sanqui/4313857 to your computer and use it in GitHub Desktop.
Diarykeeping for the truly lazy. (A Python module for ZNC, an IRC bouncer.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import znc | |
import datetime | |
DAY_BEGIN_HOUR = 4 | |
DIARY_DIR = ".diary/" | |
class diary(znc.Module): | |
description = "Diarykeeping for the truly lazy." | |
def OnModCommand(self, message): | |
try: | |
now = datetime.datetime.now() | |
filename_now = now | |
day_accurate = True | |
if now.hour <= DAY_BEGIN_HOUR: | |
filename_now = now - datetime.timedelta(days=1) | |
day_accurate = False | |
filename = filename_now.strftime("%Y-%m-%d.txt") | |
if message.startswith('.'): | |
cmd = message[1:].strip() | |
if cmd == "day": | |
self.PutModule("The current day is {}".format(filename)) | |
elif cmd == "read": | |
try: | |
with open(DIARY_DIR+filename, "r") as f: | |
for line in f.readlines(): | |
self.PutModule(line.strip()) | |
except IOError: | |
self.PutModule("Nothing written on this day!") | |
else: | |
self.PutModule("No clue what you wanted.") | |
else: | |
with open(DIARY_DIR+filename, "a") as f: | |
f.write("[{}] {}\n".format(now, message)) | |
except Exception as ex: | |
self.PutModule(str(ex)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment