last_name.py 963 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import sqlalchemy as sa
from sqlalchemy.orm import Session


def connection():
    with open("connection.txt") as f:
        return f.read()


names = {
    "f": ["玲", "丽", "莉", "娟", "绢", "洁", "秀莉", "秀丽", "芳", "芬", "媛", "依依", "柔", "小小", "莉娅", "雪", "琳"],
    "m": ["森", "林", "强", "勇", "刚", "志强", "有德", "志勇", "利国", "利民", "毅", "腾", "骏", "雄", "烈", "铁"],
    "n": ["敏", "智", "鑫", "一", "秀", "远", "希夷", "俊", "英", "之", "芝", "月", "越", "跃", "粤",
          "云", "扬", "鸥"]
}

engine = sa.create_engine(connection())
session = Session(bind=engine)
tokens = []
for k in names:
    for w in names[k]:
        tokens.append((w, k))

for pair in tokens:
    name, tend_to = pair
    session.execute("insert ignore into last_name(label, sex_tend) select :label, :tend",
                    {"label": name, "tend": tend_to})
    print(name)
session.commit()