From c55917100f1506e60f1dedec12f5622c47521cd1 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Fri, 15 Jul 2022 16:23:17 +0800 Subject: [PATCH] add utils scripts --- .gitignore | 3 ++- gears/scripts/connection.tmpl | 1 + gears/scripts/first_name.py | 30 +++++++++++++++++++++ gears/scripts/last_name.py | 29 ++++++++++++++++++++ gears/sql/first_name.sql | 50 +++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 gears/scripts/connection.tmpl create mode 100644 gears/scripts/first_name.py create mode 100644 gears/scripts/last_name.py create mode 100644 gears/sql/first_name.sql diff --git a/.gitignore b/.gitignore index 8399709..23456c2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ __pycache__ bin/ debug/ release/ -book/ \ No newline at end of file +book/ +gears/scripts/connection.txt \ No newline at end of file diff --git a/gears/scripts/connection.tmpl b/gears/scripts/connection.tmpl new file mode 100644 index 0000000..4c6a183 --- /dev/null +++ b/gears/scripts/connection.tmpl @@ -0,0 +1 @@ +mysql://mars:pwd@localhost/studio \ No newline at end of file diff --git a/gears/scripts/first_name.py b/gears/scripts/first_name.py new file mode 100644 index 0000000..a48e9b1 --- /dev/null +++ b/gears/scripts/first_name.py @@ -0,0 +1,30 @@ +import sqlalchemy as sa +from sqlalchemy.orm import Session + +def connection(): + with open("connection.txt") as f: + return f.read() + +names = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎"\ + "鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄"\ + "和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭"\ + "梅盛林刁锺徐邱骆高夏蔡田樊胡凌霍虞万支柯昝管卢莫经房裘缪干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚"\ + "程嵇邢滑裴陆荣翁荀羊於惠甄麹家封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫"\ + "甯仇栾暴甘钭厉戎祖武符刘景詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲邰从鄂索咸籍赖卓蔺屠蒙池乔阴鬱胥能苍双"\ + "闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍郤璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容"\ + "向古易慎戈廖庾终暨居衡步都耿满弘匡国文寇广禄阙东欧殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空"\ + "曾毋沙乜养鞠须丰巢关蒯相查后荆红游竺权逯盖益桓公,万俟,司马,上官,欧阳,夏侯,诸葛,闻人,东方,赫连,皇甫,尉迟,公羊,"\ + "澹台,公冶,宗政,濮阳,淳于,单于,太叔,申屠,公孙,仲孙,轩辕,令狐,锺离,宇文,长孙,慕容,鲜于,闾丘,司徒,司空,亓官,司寇,仉督,子车,"\ + "颛孙,端木,巫马,公西,漆雕,乐正,壤驷,公良,拓跋,夹谷,宰父.穀梁,晋,楚,闫,法,汝,鄢,涂,钦,段干,百里,东郭,南门,呼延,归,海,羊舌,微生,"\ + "岳,帅,缑,亢,况,後,有,琴,梁丘,左丘,东门,西门,商,牟,佘,佴,伯,赏,南宫,墨,哈,谯,笪,年,爱,阳,佟,第五,言,福" + +tokens = names.split(',') +l = [c for c in tokens[0]] +l.extend(tokens[1:]) + +engine = sa.create_engine(connection()) +session = Session(bind=engine) +for name in l: + session.execute("insert ignore into first_name(label) select :name", {"name": name}) + print(name) +session.commit() \ No newline at end of file diff --git a/gears/scripts/last_name.py b/gears/scripts/last_name.py new file mode 100644 index 0000000..1c1e0a4 --- /dev/null +++ b/gears/scripts/last_name.py @@ -0,0 +1,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() diff --git a/gears/sql/first_name.sql b/gears/sql/first_name.sql new file mode 100644 index 0000000..883cef8 --- /dev/null +++ b/gears/sql/first_name.sql @@ -0,0 +1,50 @@ +-- MySQL dump 10.13 Distrib 8.0.26, for macos11.3 (x86_64) +-- +-- Host: localhost Database: studio +-- ------------------------------------------------------ +-- Server version 8.0.26 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `first_name` +-- + +DROP TABLE IF EXISTS `first_name`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `first_name` ( + `label` char(8) NOT NULL, + PRIMARY KEY (`label`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `first_name` +-- + +LOCK TABLES `first_name` WRITE; +/*!40000 ALTER TABLE `first_name` DISABLE KEYS */; +INSERT INTO `first_name` VALUES ('丁'),('万'),('万俟'),('上官'),('东'),('东方'),('东郭'),('东门'),('严'),('丰'),('乌'),('乐'),('乐正'),('乔'),('乜'),('习'),('于'),('云'),('亓官'),('井'),('亢'),('仇'),('仉督'),('从'),('令狐'),('仰'),('仲'),('仲孙'),('任'),('伊'),('伍'),('伏'),('伯'),('何'),('佘'),('余'),('佟'),('佴'),('侯'),('俞'),('倪'),('傅'),('储'),('元'),('充'),('党'),('全'),('公'),('公冶'),('公孙'),('公羊'),('公良'),('公西'),('关'),('养'),('冀'),('冉'),('农'),('冯'),('况'),('冷'),('凌'),('凤'),('刁'),('刘'),('利'),('别'),('劳'),('勾'),('包'),('匡'),('华'),('卓'),('单'),('单于'),('南宫'),('南门'),('卜'),('卞'),('卢'),('卫'),('印'),('危'),('厉'),('厍'),('双'),('古'),('史'),('叶'),('司'),('司寇'),('司徒'),('司空'),('司马'),('吉'),('后'),('向'),('吕'),('吴'),('周'),('呼延'),('和'),('咸'),('哈'),('唐'),('商'),('喻'),('国'),('堵'),('墨'),('壤驷'),('夏'),('夏侯'),('夔'),('太叔'),('夹谷'),('奚'),('姚'),('姜'),('姬'),('娄'),('子车'),('孔'),('孙'),('孟'),('季'),('宇文'),('安'),('宋'),('宓'),('宗'),('宗政'),('宣'),('宦'),('宫'),('宰'),('宰父.穀梁'),('家'),('容'),('宿'),('寇'),('富'),('寿'),('封'),('尉迟'),('尚'),('尤'),('尹'),('居'),('屈'),('屠'),('山'),('岑'),('岳'),('崔'),('嵇'),('巢'),('左'),('左丘'),('巩'),('巫'),('巫马'),('巴'),('帅'),('师'),('席'),('常'),('干'),('平'),('年'),('幸'),('广'),('庄'),('应'),('庞'),('康'),('庾'),('廉'),('廖'),('弓'),('弘'),('张'),('强'),('归'),('彭'),('後'),('徐'),('微生'),('怀'),('惠'),('慎'),('慕'),('慕容'),('戈'),('戎'),('成'),('戚'),('戴'),('房'),('扈'),('扶'),('拓跋'),('支'),('敖'),('文'),('方'),('於'),('施'),('时'),('昌'),('明'),('易'),('昝'),('晁'),('晋'),('晏'),('景'),('暨'),('暴'),('曹'),('曾'),('有'),('朱'),('权'),('李'),('杜'),('束'),('杨'),('杭'),('松'),('林'),('柏'),('查'),('柯'),('柳'),('柴'),('栾'),('桂'),('桑'),('桓'),('梁'),('梁丘'),('梅'),('楚'),('樊'),('欧'),('欧阳'),('步'),('武'),('殳'),('段'),('段干'),('殷'),('毋'),('毕'),('毛'),('水'),('汝'),('江'),('池'),('汤'),('汪'),('汲'),('沃'),('沈'),('沙'),('法'),('洪'),('浦'),('海'),('涂'),('淳于'),('温'),('游'),('湛'),('滑'),('滕'),('满'),('漆雕'),('潘'),('澹台'),('濮'),('濮阳'),('焦'),('熊'),('燕'),('爱'),('牛'),('牟'),('牧'),('狄'),('王'),('班'),('琴'),('璩'),('甄'),('甘'),('甯'),('田'),('申'),('申屠'),('白'),('百里'),('皇甫'),('皮'),('益'),('盖'),('盛'),('相'),('瞿'),('石'),('祁'),('祖'),('祝'),('禄'),('福'),('禹'),('秋'),('秦'),('程'),('穆'),('空'),('窦'),('章'),('童'),('端木'),('竺'),('符'),('笪'),('第五'),('简'),('管'),('籍'),('米'),('糜'),('索'),('红'),('纪'),('终'),('经'),('缑'),('缪'),('罗'),('羊'),('羊舌'),('羿'),('翁'),('翟'),('耿'),('聂'),('胡'),('胥'),('能'),('臧'),('舒'),('艾'),('芮'),('花'),('苍'),('苏'),('苗'),('范'),('茅'),('茹'),('荀'),('荆'),('荣'),('莘'),('莫'),('萧'),('葛'),('董'),('蒋'),('蒙'),('蒯'),('蒲'),('蓝'),('蓟'),('蓬'),('蔚'),('蔡'),('蔺'),('薄'),('薛'),('虞'),('融'),('衡'),('袁'),('裘'),('裴'),('褚'),('西门'),('解'),('言'),('訾'),('詹'),('计'),('许'),('诸'),('诸葛'),('谈'),('谢'),('谭'),('谯'),('谷'),('贝'),('贡'),('贲'),('费'),('贺'),('贾'),('赏'),('赖'),('赫连'),('赵'),('越'),('路'),('车'),('轩辕'),('辛'),('边'),('连'),('逄'),('通'),('逯'),('邓'),('邢'),('那'),('邬'),('邰'),('邱'),('邴'),('邵'),('邹'),('郁'),('郎'),('郏'),('郑'),('郗'),('郜'),('郝'),('郤'),('郦'),('郭'),('都'),('鄂'),('鄢'),('酆'),('金'),('钦'),('钭'),('钮'),('钱'),('锺'),('锺离'),('长孙'),('闫'),('闵'),('闻'),('闻人'),('闾丘'),('阎'),('阙'),('阚'),('阮'),('阳'),('阴'),('陆'),('陈'),('陶'),('隆'),('隗'),('雍'),('雷'),('霍'),('靳'),('鞠'),('韦'),('韩'),('韶'),('项'),('须'),('顾'),('颛孙'),('颜'),('饶'),('马'),('骆'),('高'),('鬱'),('魏'),('鱼'),('鲁'),('鲍'),('鲜于'),('麹'),('麻'),('黄'),('黎'),('齐'),('龙'),('龚'); +/*!40000 ALTER TABLE `first_name` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2022-07-13 21:26:32 -- GitLab