FTP uploading, doesn't create any directories though
This commit is contained in:
parent
b6cdd5275f
commit
d38fe90fce
1 changed files with 32 additions and 2 deletions
34
logbot.py
34
logbot.py
|
@ -32,6 +32,7 @@ __license__ = "GPL2"
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from ftplib import FTP
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -52,7 +53,12 @@ PORT = 6667
|
||||||
SERVER_PASS = None
|
SERVER_PASS = None
|
||||||
CHANNELS=["#keryx"]
|
CHANNELS=["#keryx"]
|
||||||
NICK = "timber"
|
NICK = "timber"
|
||||||
NICK_PASS = None
|
NICK_PASS = ""
|
||||||
|
|
||||||
|
FTP_SERVER = ""
|
||||||
|
FTP_USER = ""
|
||||||
|
FTP_PASS = ""
|
||||||
|
FTP_FOLDER = ""
|
||||||
|
|
||||||
default_format = {
|
default_format = {
|
||||||
"action" : '<span class="person" style="color:%color%">* %user% %message%</span>',
|
"action" : '<span class="person" style="color:%color%">* %user% %message%</span>',
|
||||||
|
@ -132,6 +138,8 @@ class Logbot(SingleServerIRCBot):
|
||||||
|
|
||||||
self.chans = [x.lower() for x in channels]
|
self.chans = [x.lower() for x in channels]
|
||||||
self.format = format
|
self.format = format
|
||||||
|
self.set_ftp()
|
||||||
|
self.count = 0
|
||||||
|
|
||||||
print "Logbot %s" % __version__
|
print "Logbot %s" % __version__
|
||||||
print "Connecting to %s:%i..." % (server, port)
|
print "Connecting to %s:%i..." % (server, port)
|
||||||
|
@ -143,6 +151,9 @@ class Logbot(SingleServerIRCBot):
|
||||||
def color(self, user):
|
def color(self, user):
|
||||||
return "#%s" % md5(user).hexdigest()[:6]
|
return "#%s" % md5(user).hexdigest()[:6]
|
||||||
|
|
||||||
|
def set_ftp(self, ftp=None):
|
||||||
|
self.ftp = ftp
|
||||||
|
|
||||||
def format_event(self, name, event, params):
|
def format_event(self, name, event, params):
|
||||||
msg = self.format[name]
|
msg = self.format[name]
|
||||||
for key, val in params.iteritems():
|
for key, val in params.iteritems():
|
||||||
|
@ -173,6 +184,18 @@ class Logbot(SingleServerIRCBot):
|
||||||
|
|
||||||
for chan in chans:
|
for chan in chans:
|
||||||
self.append_log_msg(chan, msg)
|
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):
|
def append_log_msg(self, channel, msg):
|
||||||
print "%s >>> %s" % (channel, msg)
|
print "%s >>> %s" % (channel, msg)
|
||||||
|
@ -283,10 +306,17 @@ def main():
|
||||||
# Start the bot
|
# Start the bot
|
||||||
bot = Logbot(SERVER, PORT, SERVER_PASS, CHANNELS, NICK, NICK_PASS)
|
bot = Logbot(SERVER, PORT, SERVER_PASS, CHANNELS, NICK, NICK_PASS)
|
||||||
try:
|
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()
|
bot.start()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
if FTP_SERVER: f.quit()
|
||||||
bot.quit()
|
bot.quit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue