python背单词

python背单词程序,持续完善ing

import time
import pymysql
from playsound import playsound
import requests
import os
def word_input():
    word_list = input("请输入单元数:")
    flag = 0
    while flag!=1:
        word = input("请输入单词:")
        if word == "0":
            break
        insert_sql = "INSERT INTO cet4word(id,list,word,word_main) VALUES (NULL,"+ word_list + ",'"+word+"',' ')"
        cursor.execute(insert_sql)
def xz():
    word_list = input("请输入你要下载的单元:")
    #https://lex-audio.useremarkable.com/mp3/according__gb_1.mp3
    sql = "select* from cet4word where list="+str(word_list)
    result = cursor.execute(sql)
    info = cursor.fetchall()
    j = 1
    for i in info:
        #print(i[2])
        #http://dict.youdao.com/dictvoice?type=0&audio=
        url = "http://dict.youdao.com/dictvoice?type=0&audio="+i[2]
        res = requests.get(url)
        music = res.content
        file_name = 'E:\CET4\LIST'+str(word_list)+'/'+str(j) +"."+i[2]+'.mp3'
        j += 1
        with open(file_name, 'ab') as file:  # 保存到本地的文件名
            file.write(res.content)
            file.flush()
def bf():
    list = input("播放的单元数:")
    wjj = "E:\CET4\LIST" + list
    filenames = os.listdir(wjj)
    for i in filenames:
        file = wjj+"/"+i
        playsound(file)
        time.sleep(0.1)
        playsound(file)
        time.sleep(0.1)
        playsound(file)
        time.sleep(2)
connect = pymysql.connect(
    host='localhost',
    user='root',
    port=3306,
    password=' ',
    db='cet4',
    charset='utf8',
    autocommit=True,    # 如果插入数据,, 是否自动提交? 和conn.commit()功能一致。
)

cursor=connect.cursor()
print("1.录入单词\n2.下载音频\n3.播放音频")
cmd = input("请输入:")
if cmd == "1":
    word_input()
if cmd == "2":
    xz()
if cmd == "3":
    bf()
cursor.close()
connect.close()
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wooovi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值