459 lines
13 KiB
Python
459 lines
13 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""插入所有词汇书数据到数据库"""
|
||
|
||
import mysql.connector
|
||
from datetime import datetime
|
||
|
||
# 数据库配置
|
||
db_config = {
|
||
'host': 'localhost',
|
||
'port': 3306,
|
||
'user': 'root',
|
||
'password': 'JKjk20011115',
|
||
'database': 'ai_english_learning',
|
||
'charset': 'utf8mb4'
|
||
}
|
||
|
||
# 所有词汇书数据
|
||
vocabulary_books = [
|
||
# 学段基础词汇
|
||
{
|
||
'id': 'primary_core_1000',
|
||
'name': '小学英语核心词汇',
|
||
'description': '小学阶段必备的1000个核心词汇,涵盖日常生活场景',
|
||
'category': '学段基础词汇',
|
||
'level': 'beginner',
|
||
'total_words': 728, # 已导入
|
||
'icon': '🎈',
|
||
'color': '#E91E63',
|
||
'sort_order': 1
|
||
},
|
||
{
|
||
'id': 'junior_high_1500',
|
||
'name': '初中英语词汇',
|
||
'description': '初中阶段1500-2500词汇,结合教材要求',
|
||
'category': '学段基础词汇',
|
||
'level': 'elementary',
|
||
'total_words': 1500,
|
||
'icon': '📝',
|
||
'color': '#00BCD4',
|
||
'sort_order': 2
|
||
},
|
||
{
|
||
'id': 'senior_high_3500',
|
||
'name': '高中英语词汇',
|
||
'description': '高中阶段2500-3500词汇,涵盖课标与高考高频词',
|
||
'category': '学段基础词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 3500,
|
||
'icon': '📕',
|
||
'color': '#FF5722',
|
||
'sort_order': 3
|
||
},
|
||
{
|
||
'id': 'college_textbook',
|
||
'name': '大学英语教材词汇',
|
||
'description': '大学英语精读/泛读配套词汇',
|
||
'category': '学段基础词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 2000,
|
||
'icon': '📚',
|
||
'color': '#3F51B5',
|
||
'sort_order': 4
|
||
},
|
||
|
||
# 国内应试类词汇
|
||
{
|
||
'id': 'cet4_core_2500',
|
||
'name': '大学英语四级核心词汇',
|
||
'description': '涵盖CET-4考试核心词汇2500个',
|
||
'category': '国内应试类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 2500,
|
||
'icon': '📚',
|
||
'color': '#4CAF50',
|
||
'sort_order': 11
|
||
},
|
||
{
|
||
'id': 'cet6_core_3000',
|
||
'name': '大学英语六级核心词汇',
|
||
'description': '涵盖CET-6考试核心词汇3000个',
|
||
'category': '国内应试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 3000,
|
||
'icon': '📖',
|
||
'color': '#2196F3',
|
||
'sort_order': 12
|
||
},
|
||
{
|
||
'id': 'postgraduate_vocabulary',
|
||
'name': '考研英语核心词汇',
|
||
'description': '考研英语必备核心词汇',
|
||
'category': '国内应试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 5500,
|
||
'icon': '🎓',
|
||
'color': '#9C27B0',
|
||
'sort_order': 13
|
||
},
|
||
{
|
||
'id': 'tem4_vocabulary',
|
||
'name': '专四词汇(TEM-4)',
|
||
'description': '英语专业四级考试词汇',
|
||
'category': '国内应试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 8000,
|
||
'icon': '📘',
|
||
'color': '#FF9800',
|
||
'sort_order': 14
|
||
},
|
||
{
|
||
'id': 'tem8_vocabulary',
|
||
'name': '专八词汇(TEM-8)',
|
||
'description': '英语专业八级考试词汇',
|
||
'category': '国内应试类词汇',
|
||
'level': 'expert',
|
||
'total_words': 12000,
|
||
'icon': '📙',
|
||
'color': '#F44336',
|
||
'sort_order': 15
|
||
},
|
||
|
||
# 出国考试类词汇
|
||
{
|
||
'id': 'ielts_high_3500',
|
||
'name': '雅思高频词汇',
|
||
'description': '雅思考试高频词汇3500个',
|
||
'category': '出国考试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 3500,
|
||
'icon': '🌟',
|
||
'color': '#9C27B0',
|
||
'sort_order': 21
|
||
},
|
||
{
|
||
'id': 'ielts_general',
|
||
'name': '雅思通用词汇(IELTS General)',
|
||
'description': '雅思通用类考试核心词汇',
|
||
'category': '出国考试类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 6000,
|
||
'icon': '⭐',
|
||
'color': '#673AB7',
|
||
'sort_order': 22
|
||
},
|
||
{
|
||
'id': 'toefl_high_3500',
|
||
'name': '托福高频词汇',
|
||
'description': '托福考试高频词汇3500个',
|
||
'category': '出国考试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 3500,
|
||
'icon': '🎓',
|
||
'color': '#FF9800',
|
||
'sort_order': 23
|
||
},
|
||
{
|
||
'id': 'toeic_vocabulary',
|
||
'name': '托业词汇(TOEIC)',
|
||
'description': '托业考试职场应用词汇',
|
||
'category': '出国考试类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 6000,
|
||
'icon': '💼',
|
||
'color': '#00BCD4',
|
||
'sort_order': 24
|
||
},
|
||
{
|
||
'id': 'gre_vocabulary',
|
||
'name': 'GRE词汇',
|
||
'description': 'GRE学术/研究生申请词汇',
|
||
'category': '出国考试类词汇',
|
||
'level': 'expert',
|
||
'total_words': 15000,
|
||
'icon': '🔬',
|
||
'color': '#E91E63',
|
||
'sort_order': 25
|
||
},
|
||
{
|
||
'id': 'gmat_vocabulary',
|
||
'name': 'GMAT词汇',
|
||
'description': 'GMAT商科/管理类研究生词汇',
|
||
'category': '出国考试类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 8000,
|
||
'icon': '📊',
|
||
'color': '#4CAF50',
|
||
'sort_order': 26
|
||
},
|
||
{
|
||
'id': 'sat_vocabulary',
|
||
'name': 'SAT词汇',
|
||
'description': 'SAT美本申请词汇',
|
||
'category': '出国考试类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 5000,
|
||
'icon': '🎯',
|
||
'color': '#FF5722',
|
||
'sort_order': 27
|
||
},
|
||
|
||
# 职业与专业类词汇
|
||
{
|
||
'id': 'business_core_1000',
|
||
'name': '商务英语核心词汇',
|
||
'description': '商务场景常用核心词汇1000个',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 1000,
|
||
'icon': '💼',
|
||
'color': '#607D8B',
|
||
'sort_order': 31
|
||
},
|
||
{
|
||
'id': 'bec_preliminary',
|
||
'name': '商务英语初级(BEC Preliminary)',
|
||
'description': 'BEC初级商务英语词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 3000,
|
||
'icon': '📋',
|
||
'color': '#00BCD4',
|
||
'sort_order': 32
|
||
},
|
||
{
|
||
'id': 'bec_vantage',
|
||
'name': '商务英语中级(BEC Vantage)',
|
||
'description': 'BEC中级商务英语词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 4000,
|
||
'icon': '📊',
|
||
'color': '#2196F3',
|
||
'sort_order': 33
|
||
},
|
||
{
|
||
'id': 'bec_higher',
|
||
'name': '商务英语高级(BEC Higher)',
|
||
'description': 'BEC高级商务英语词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 5000,
|
||
'icon': '📈',
|
||
'color': '#4CAF50',
|
||
'sort_order': 34
|
||
},
|
||
{
|
||
'id': 'mba_finance',
|
||
'name': 'MBA/金融词汇',
|
||
'description': 'MBA、金融、会计、经济学专业词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 6000,
|
||
'icon': '💰',
|
||
'color': '#FF9800',
|
||
'sort_order': 35
|
||
},
|
||
{
|
||
'id': 'medical_english',
|
||
'name': '医学英语词汇',
|
||
'description': '医学专业英语词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 8000,
|
||
'icon': '⚕️',
|
||
'color': '#F44336',
|
||
'sort_order': 36
|
||
},
|
||
{
|
||
'id': 'legal_english',
|
||
'name': '法律英语词汇',
|
||
'description': '法律专业英语词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 5000,
|
||
'icon': '⚖️',
|
||
'color': '#9C27B0',
|
||
'sort_order': 37
|
||
},
|
||
{
|
||
'id': 'it_engineering',
|
||
'name': '工程与IT英语',
|
||
'description': '计算机科学、人工智能、软件工程词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'intermediate',
|
||
'total_words': 4000,
|
||
'icon': '💻',
|
||
'color': '#3F51B5',
|
||
'sort_order': 38
|
||
},
|
||
{
|
||
'id': 'academic_english',
|
||
'name': '学术英语(EAP)',
|
||
'description': '学术英语写作/阅读/科研常用词汇',
|
||
'category': '职业与专业类词汇',
|
||
'level': 'advanced',
|
||
'total_words': 6000,
|
||
'icon': '🔬',
|
||
'color': '#00BCD4',
|
||
'sort_order': 39
|
||
},
|
||
|
||
# 功能型词库
|
||
{
|
||
'id': 'word_roots_affixes',
|
||
'name': '词根词缀词汇',
|
||
'description': '帮助记忆与扩展的词根词缀词汇',
|
||
'category': '功能型词库',
|
||
'level': 'intermediate',
|
||
'total_words': 3000,
|
||
'icon': '🌱',
|
||
'color': '#4CAF50',
|
||
'sort_order': 41
|
||
},
|
||
{
|
||
'id': 'synonyms_antonyms',
|
||
'name': '同义词/反义词库',
|
||
'description': '同义词、反义词、近义搭配库',
|
||
'category': '功能型词库',
|
||
'level': 'intermediate',
|
||
'total_words': 2500,
|
||
'icon': '🔄',
|
||
'color': '#2196F3',
|
||
'sort_order': 42
|
||
},
|
||
{
|
||
'id': 'daily_spoken_collocations',
|
||
'name': '日常口语搭配库',
|
||
'description': '日常口语常用搭配库',
|
||
'category': '功能型词库',
|
||
'level': 'beginner',
|
||
'total_words': 1500,
|
||
'icon': '💬',
|
||
'color': '#FF9800',
|
||
'sort_order': 43
|
||
},
|
||
{
|
||
'id': 'academic_spoken_collocations',
|
||
'name': '学术口语搭配库',
|
||
'description': '学术口语常用搭配库',
|
||
'category': '功能型词库',
|
||
'level': 'advanced',
|
||
'total_words': 2000,
|
||
'icon': '🎤',
|
||
'color': '#9C27B0',
|
||
'sort_order': 44
|
||
},
|
||
{
|
||
'id': 'academic_writing_collocations',
|
||
'name': '学术写作搭配库',
|
||
'description': '学术写作常用搭配库(Collocations)',
|
||
'category': '功能型词库',
|
||
'level': 'advanced',
|
||
'total_words': 2500,
|
||
'icon': '✍️',
|
||
'color': '#E91E63',
|
||
'sort_order': 45
|
||
},
|
||
{
|
||
'id': 'daily_life_english',
|
||
'name': '日常生活英语',
|
||
'description': '旅游、点餐、购物、出行、租房等日常生活英语',
|
||
'category': '功能型词库',
|
||
'level': 'beginner',
|
||
'total_words': 2000,
|
||
'icon': '🏠',
|
||
'color': '#00BCD4',
|
||
'sort_order': 46
|
||
},
|
||
]
|
||
|
||
def main():
|
||
try:
|
||
# 连接数据库
|
||
conn = mysql.connector.connect(**db_config)
|
||
cursor = conn.cursor()
|
||
|
||
print(f"📚 准备插入 {len(vocabulary_books)} 个词汇书...")
|
||
|
||
# 插入SQL
|
||
insert_sql = """
|
||
INSERT INTO ai_vocabulary_books
|
||
(id, name, description, category, level, total_words, icon, color, is_system, is_active, sort_order, created_at, updated_at)
|
||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, TRUE, TRUE, %s, %s, %s)
|
||
ON DUPLICATE KEY UPDATE
|
||
name = VALUES(name),
|
||
description = VALUES(description),
|
||
category = VALUES(category),
|
||
level = VALUES(level),
|
||
icon = VALUES(icon),
|
||
color = VALUES(color),
|
||
sort_order = VALUES(sort_order),
|
||
updated_at = VALUES(updated_at)
|
||
"""
|
||
|
||
success_count = 0
|
||
update_count = 0
|
||
|
||
for book in vocabulary_books:
|
||
now = datetime.now()
|
||
|
||
# 检查是否已存在
|
||
cursor.execute("SELECT id FROM ai_vocabulary_books WHERE id = %s", (book['id'],))
|
||
exists = cursor.fetchone()
|
||
|
||
cursor.execute(insert_sql, (
|
||
book['id'],
|
||
book['name'],
|
||
book['description'],
|
||
book['category'],
|
||
book['level'],
|
||
book['total_words'],
|
||
book['icon'],
|
||
book['color'],
|
||
book['sort_order'],
|
||
now,
|
||
now
|
||
))
|
||
|
||
if exists:
|
||
update_count += 1
|
||
print(f"🔄 更新词汇书: {book['name']} ({book['category']})")
|
||
else:
|
||
success_count += 1
|
||
print(f"✅ 插入词汇书: {book['name']} ({book['category']})")
|
||
|
||
conn.commit()
|
||
|
||
print(f"\n🎉 完成!")
|
||
print(f"✅ 新增: {success_count} 个词汇书")
|
||
print(f"🔄 更新: {update_count} 个词汇书")
|
||
print(f"📊 总计: {success_count + update_count} 个词汇书")
|
||
|
||
# 按分类统计
|
||
cursor.execute("""
|
||
SELECT category, COUNT(*) as count
|
||
FROM ai_vocabulary_books
|
||
WHERE is_system = TRUE AND is_active = TRUE
|
||
GROUP BY category
|
||
ORDER BY MIN(sort_order)
|
||
""")
|
||
|
||
print(f"\n📋 分类统计:")
|
||
for row in cursor.fetchall():
|
||
print(f" {row[0]}: {row[1]} 个词汇书")
|
||
|
||
except mysql.connector.Error as err:
|
||
print(f"❌ 数据库错误: {err}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
finally:
|
||
if cursor:
|
||
cursor.close()
|
||
if conn:
|
||
conn.close()
|
||
|
||
if __name__ == '__main__':
|
||
main()
|