From d38fe90fceae82f40d2dfa1174ac59edac6974e3 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sat, 11 Dec 2010 16:16:56 -0600 Subject: FTP uploading, doesn't create any directories though --- logbot.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'logbot.py') diff --git a/logbot.py b/logbot.py index 53f1444..424f91b 100644 --- a/logbot.py +++ b/logbot.py @@ -32,6 +32,7 @@ __license__ = "GPL2" import os +from ftplib import FTP from time import strftime try: @@ -52,7 +53,12 @@ PORT = 6667 SERVER_PASS = None CHANNELS=["#keryx"] NICK = "timber" -NICK_PASS = None +NICK_PASS = "" + +FTP_SERVER = "" +FTP_USER = "" +FTP_PASS = "" +FTP_FOLDER = "" default_format = { "action" : '* %user% %message%', @@ -132,6 +138,8 @@ class Logbot(SingleServerIRCBot): self.chans = [x.lower() for x in channels] self.format = format + self.set_ftp() + self.count = 0 print "Logbot %s" % __version__ print "Connecting to %s:%i..." % (server, port) @@ -143,6 +151,9 @@ class Logbot(SingleServerIRCBot): def color(self, user): return "#%s" % md5(user).hexdigest()[:6] + def set_ftp(self, ftp=None): + self.ftp = ftp + def format_event(self, name, event, params): msg = self.format[name] for key, val in params.iteritems(): @@ -173,6 +184,18 @@ class Logbot(SingleServerIRCBot): for chan in chans: self.append_log_msg(chan, msg) + + self.count += 1 + + if self.ftp and self.count > 25: + self.count = 0 + + for root, dirs, files in os.walk("logs"): + #TODO: Create folders + + for fname in files: + full_fname = os.path.join(root, fname) + self.ftp.storbinary("STOR %s" % fname, open(full_fname, "rb")) def append_log_msg(self, channel, msg): print "%s >>> %s" % (channel, msg) @@ -283,10 +306,17 @@ def main(): # Start the bot bot = Logbot(SERVER, PORT, SERVER_PASS, CHANNELS, NICK, NICK_PASS) try: + # Connect to FTP + if FTP_SERVER: + f = FTP(FTP_SERVER, FTP_USER, FTP_PASS) + f.cwd(FTP_FOLDER) + bot.set_ftp(f) + bot.start() except KeyboardInterrupt: + if FTP_SERVER: f.quit() bot.quit() if __name__ == "__main__": - main() \ No newline at end of file + main() -- cgit v1.2.3-54-g00ecf