summaryrefslogtreecommitdiffstats
path: root/upgrade
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-04-12 01:08:33 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-04-12 01:08:33 +0800
commit82550dfd7ab76c549cc6304edc6e623663e3e8ba (patch)
tree7908f6089d7a66fc465d33361e96987feadbd940 /upgrade
parentdbc9f181f9893ca95951ff566ece95d421622d90 (diff)
downloadpttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar.gz
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar.bz2
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar.lz
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar.xz
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.tar.zst
pttbbs-82550dfd7ab76c549cc6304edc6e623663e3e8ba.zip
- reglog: add register.log -> sqlite3db conversion script.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4132 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'upgrade')
-rw-r--r--upgrade/merge_sob.c2
-rwxr-xr-xupgrade/r4132_reglog2db.py108
2 files changed, 109 insertions, 1 deletions
diff --git a/upgrade/merge_sob.c b/upgrade/merge_sob.c
index dd4f0dd0..91b97e37 100644
--- a/upgrade/merge_sob.c
+++ b/upgrade/merge_sob.c
@@ -191,7 +191,7 @@ m_sob(void)
strcat(msg, "匯入好友名單\n");
}
sprintf(buf, "帳號匯入報告 %s -> %s ", userid, cuser.userid);
- post_msg(GLOBAL_SECURITY, buf, msg, "[系統安全局]");
+ post_msg(BN_SECURITY, buf, msg, "[系統安全局]");
vmsg("恭喜您完成帳號變身..");
return 0;
diff --git a/upgrade/r4132_reglog2db.py b/upgrade/r4132_reglog2db.py
new file mode 100755
index 00000000..5fe7ed49
--- /dev/null
+++ b/upgrade/r4132_reglog2db.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+#
+# parse register.log and create reglog.db
+#
+# please first test and fix your register.log, then
+# try writing to database.
+#
+# Create: piaip
+
+# python 2.5:
+#import sqlite3
+# python 2.4 or prior:
+from pysqlite2 import dbapi2 as sqlite3
+
+import sys
+import time
+
+def initdb(dbfn) :
+ db = sqlite3.connect(dbfn)
+ c = db.cursor()
+ # separate the tables to 'approved' and 'rejected',
+ # since the 'rejected' is rarely used...
+ c.execute('create table if not exists approved ' +
+ '(uid text, name text, career text, ' +
+ ' addr text, phone text, date text, approved text)');
+ c.execute('create table if not exists rejected ' +
+ '(uid text, name text, career text, ' +
+ ' addr text, phone text, date text, rejected text)');
+ return (db, c)
+
+def processblk(m) :
+ #print "process blk!"
+ if not m.has_key('uid') :
+ print "no uid record at line: ", lineno
+ sys.exit(-1)
+ if (not m.has_key('approved')) and (not m.has_key('rejected')) :
+ print "invalid record (action?) at line: ", lineno
+ sys.exit(-1)
+ if c != None :
+ type = 'rejected';
+ if m.has_key('approved') : type = 'approved';
+ # write into database
+ sql = 'insert into ' + type + ' values (?,?,?,?,?,?,?)';
+ # follow the orders
+ c.execute(sql, (m['uid'], m['name'], m['career'], m['addr'], m['phone'], m['date'], m[type]));
+
+# default input
+fn = "register.log"
+dbfn= ""
+db = None
+c = None
+if len (sys.argv) < 1 :
+ print "syntax:", sys.argv[0], "register.log [reglog.db]"
+ sys.exit(0)
+if len (sys.argv) > 1 :
+ fn = sys.argv[1]
+if len (sys.argv) > 2 :
+ dbfn = sys.argv[2]
+
+print "Opening ", fn, "..."
+f = open(fn, "rt")
+
+if dbfn != '' :
+ (db, c) = initdb(dbfn)
+
+m={}
+lineno = 0
+tickets = 0
+for s in f :
+ lineno = lineno +1
+ # for each line...
+ if s.startswith("num:") : continue
+ if s.startswith("email:") : continue
+ if s.startswith("ident:") : continue
+ if s.startswith("]") : continue
+ if s.startswith("----") :
+ # ready to build new one
+ processblk(m)
+ m = {}
+ tickets = tickets +1
+ if tickets % 10000 == 0 :
+ if db : db.commit()
+ print tickets, "forms processed."
+ continue
+ v = s.split(': ', 1)
+ if len(v) != 2 :
+ print "error at line ", lineno
+ sys.exit(-1)
+ k = v[0].lower()
+ if (m.has_key(k)) :
+ print "key duplicated at line ", lineno
+ sys.exit(-1)
+ # convert timestamp
+ v = v[1].strip()
+ if (k == 'date') :
+ # strip final weekday
+ v = v.split(' ') # mdy HMS abrv
+ if len(v) < 2 or len(v) > 3 :
+ print "invalid date entry at line ", lineno
+ sys.exit(-1)
+ v = v[0] + ' ' + v[1]
+ # build timestamp
+ v = str(int(time.mktime(time.strptime(v, "%m/%d/%Y %H:%M:%S"))))
+ m[k] = v
+
+f.close()
+
+# vim:sw=4:expandtab