reorganizing project directories, part 1
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
"""
|
||||
factfiles-to-facts - insert facts from flat file to database
|
||||
Copyright (C) 2010 Brian S. Stephan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import getpass
|
||||
import os
|
||||
import sqlite3
|
||||
import socket
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-f', '--factfile')
|
||||
parser.add_argument('-c', '--category')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.factfile == None or args.category == None:
|
||||
print('script needs both -c (category) and -f (filename)')
|
||||
sys.exit(2)
|
||||
|
||||
# database
|
||||
dbfile = 'dr.botzo.data'
|
||||
db = sqlite3.connect(dbfile)
|
||||
|
||||
# open file
|
||||
if os.path.isfile(args.factfile):
|
||||
with open(args.factfile, 'r') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
try:
|
||||
line = line.rstrip()
|
||||
print('inserting \'' + line + '\'')
|
||||
db.execute('''INSERT INTO facts_facts (category, fact, who, userhost)
|
||||
VALUES (?,?,?,?)''', (args.category, line.decode('utf-8', 'ignore'), getpass.getuser(), getpass.getuser() + '@' + socket.getfqdn()))
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
sys.exit(2)
|
||||
|
||||
db.commit()
|
||||
else:
|
||||
print('filename \'' + whats[0] + '\' doesn\'t exist')
|
||||
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
||||
@@ -1,58 +0,0 @@
|
||||
"""
|
||||
import-file-into-markov_chain.py
|
||||
Copyright (C) 2011 Brian S. Stephan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description='Import lines into the specified context_id.')
|
||||
parser.add_argument('context_id', metavar='CONTEXT', type=int, nargs=1)
|
||||
args = parser.parse_args()
|
||||
print(args.context_id[0])
|
||||
|
||||
db = sqlite3.connect('dr.botzo.data')
|
||||
db.row_factory = sqlite3.Row
|
||||
|
||||
cur = db.cursor()
|
||||
statement = 'INSERT INTO markov_chain (k1, k2, v, context_id) VALUES (?, ?, ?, ?)'
|
||||
for line in sys.stdin:
|
||||
# set up the head of the chain
|
||||
w1 = '__start1'
|
||||
w2 = '__start2'
|
||||
|
||||
# for each word pair, add the next word to the dictionary
|
||||
for word in line.split():
|
||||
try:
|
||||
cur.execute(statement, (w1.decode('utf-8', 'replace'), w2.decode('utf-8', 'replace'), word.decode('utf-8', 'replace'), args.context_id[0]))
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
w1, w2 = w2, word
|
||||
|
||||
try:
|
||||
cur.execute(statement, (w1.decode('utf-8', 'replace'), w2.decode('utf-8', 'replace'), '__stop', args.context_id[0]))
|
||||
db.commit()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
@@ -1,36 +0,0 @@
|
||||
from ConfigParser import ConfigParser, NoOptionError
|
||||
import os
|
||||
import sys
|
||||
|
||||
from seen.models import SeenNick
|
||||
|
||||
import MySQLdb as mdb
|
||||
|
||||
config_file = 'dr.botzo.cfg'
|
||||
config = ConfigParser()
|
||||
config.read(os.path.expanduser(config_file))
|
||||
|
||||
dbhost = config.get('dr.botzo', 'dbhost')
|
||||
dbuser = config.get('dr.botzo', 'dbuser')
|
||||
dbpass = config.get('dr.botzo', 'dbpass')
|
||||
dbname = config.get('dr.botzo', 'dbname')
|
||||
|
||||
db = mdb.connect(dbhost, dbuser, dbpass, dbname, charset='utf8', use_unicode=True)
|
||||
try:
|
||||
cur = db.cursor()
|
||||
query = '''
|
||||
SELECT * FROM seen_nicks
|
||||
'''
|
||||
cur.execute(query)
|
||||
for row in cur.fetchall():
|
||||
seen_nick = SeenNick()
|
||||
seen_nick.nick = row[0]
|
||||
seen_nick.channel = row[1]
|
||||
seen_nick.host = row[2]
|
||||
seen_nick.seen_time = row[3]
|
||||
seen_nick.what = row[4]
|
||||
seen_nick.save()
|
||||
except NoOptionError as noe:
|
||||
sys.exit("Aborted due to error in config: {0:s}".format(str(noe)))
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
@@ -1,121 +0,0 @@
|
||||
"""
|
||||
procmail-to-dispatch.py --- use dr.botzo's Dispatch to send mail notifications
|
||||
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import getpass
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import xmlrpc.client
|
||||
|
||||
# set up some basic logging
|
||||
logger = logging.getLogger()
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# set up config flags
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-f', '--filename')
|
||||
parser.add_argument('-k', '--key')
|
||||
parser.add_argument('-l', '--location')
|
||||
parser.add_argument('-u', '--user')
|
||||
args = parser.parse_args()
|
||||
|
||||
if (args.filename == None or args.key == None or args.user == None or
|
||||
args.location == None):
|
||||
print("script needs -f/--filename (location of .procmailrc.log) -k/--key (dispatch key to use) "
|
||||
"-l/--location (url to connect to) -u/--user (user to authenticate to XML-RPC as)")
|
||||
sys.exit(2)
|
||||
|
||||
password = getpass.getpass("password for {0:s}: ".format(args.user))
|
||||
|
||||
drbotzo = xmlrpc.client.ServerProxy("https://{0:s}:{1:s}@{2:s}".format(args.user, password, args.location))
|
||||
if 'dispatch' not in drbotzo.system.listMethods():
|
||||
print("remote dr.botzo instance doesn't seem to implement 'dispatch'!")
|
||||
sys.exit(2)
|
||||
|
||||
file = open(args.filename, 'r')
|
||||
|
||||
folderre = re.compile("^ Folder: (\S+)\s+\d+$")
|
||||
senderre = re.compile("^From: (.*)$")
|
||||
subjectre = re.compile("^Subject: (.*)$")
|
||||
|
||||
# start file at the end
|
||||
st_results = os.stat(args.filename)
|
||||
st_size = st_results[6]
|
||||
file.seek(st_size)
|
||||
|
||||
def get_mail_items(filename):
|
||||
sender = None
|
||||
subject = None
|
||||
|
||||
for num, line in enumerate(open(filename)):
|
||||
if senderre.search(line):
|
||||
match = senderre.search(line)
|
||||
sender = match.group(1)
|
||||
if subjectre.search(line):
|
||||
match = subjectre.search(line)
|
||||
subject = match.group(1)
|
||||
|
||||
if sender and subject:
|
||||
return (sender, subject)
|
||||
|
||||
if sender:
|
||||
return (sender, "[no subject]")
|
||||
|
||||
while 1:
|
||||
try:
|
||||
filename = None
|
||||
|
||||
where = file.tell()
|
||||
line = file.readline()
|
||||
if not line:
|
||||
time.sleep(1)
|
||||
file.seek(where)
|
||||
else:
|
||||
if folderre.search(line):
|
||||
sender = None
|
||||
subject = None
|
||||
|
||||
match = folderre.search(line)
|
||||
filename = match.group(1)
|
||||
|
||||
# ignore /dev/null, of course
|
||||
if filename == "/dev/null":
|
||||
logger.debug("skipping message forwarded to /dev/null")
|
||||
continue
|
||||
|
||||
# ignore Spam
|
||||
if filename.find(".Spam") > 0:
|
||||
logger.debug("skipping spam '{0:s}'".format(filename))
|
||||
continue
|
||||
|
||||
# try opening the actual path. this is a bit racey
|
||||
logger.debug("trying to open '{0:s}'".format(filename))
|
||||
if os.path.isfile(filename):
|
||||
logger.debug("opening '{0:s}'".format(filename))
|
||||
(sender, subject) = get_mail_items(filename)
|
||||
else:
|
||||
# ok... maybe something already moved it into cur. in addition
|
||||
# they probably added flags at the end
|
||||
filepattern = filename.replace("/new", "/cur") + "*"
|
||||
for globhit in glob.glob(filepattern):
|
||||
logger.debug("trying to open '{0:s}'".format(globhit))
|
||||
if os.path.isfile(globhit):
|
||||
logger.debug("opening '{0:s}'".format(globhit))
|
||||
(sender, subject) = get_mail_items(globhit)
|
||||
|
||||
if sender and subject:
|
||||
logger.debug("notifying: '{0:s}' from {1:s}".format(subject, sender))
|
||||
drbotzo.dispatch(args.key, "'{0:s}' from {1:s}".format(subject, sender))
|
||||
except UnicodeDecodeError as e:
|
||||
logger.error("Error: " + str(e) + ", skipping")
|
||||
pass
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
Reference in New Issue
Block a user