from os import path
import pickle
DB_dir = "~tutimura/public_html/cgi-bin/passwd/"
outdb = {}
for dbpath in ["name.txt", "name3.txt"]:
dbpath = path.expanduser(DB_dir + dbpath)
with open(dbpath, "r") as f:
for line in f.readlines():
print (line, line.count('\t'))
if not line or line.startswith("#"): continue
if line.count('\t') == 2:
no_, reading, name = line.split("\t")
else:
no_, reading, name, email = line.split("\t")
if name.count(" ") == 2:
first_n, family_n, note = name.split(" ")
name = first_n + " " + family_n
name = name.strip()
outdb[no_] = {"name": name, "reading": reading}
maildb = {}
mailpath = path.expanduser(DB_dir + "mail.txt")
with open(mailpath, "r") as f:
for line in f.readlines():
if not line: continue
line = line.strip()
tpl = line.split("\t")
if len(tpl) == 2:
no_, mailadr = tpl
dep = note = ""
elif len(tpl) == 3:
no_, mailadr, dep = tpl
note = ""
elif len(tpl) == 4:
no_, mailadr, dep, note = tpl
id_ = mailadr.split("@")[0]
if no_ in outdb:
name = outdb[no_]["name"]
reading = outdb[no_]["reading"]
else:
name = ""
reading = ""
maildb[id_] = { "name": name, "reading": reading,
"no": no_, "dep": dep, "note": note}
with open("name.pickle", "wb") as out:
pickle.dump(maildb, out)