|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Cool_Breeze 于 2020-7-17 21:41 编辑
更新了! 你们在测试一下看看还有没有bug!
- #coding=utf-8
- #By Gin
- #2020/7/17
- #Rev 02
- import os
- import re
- ch_dict = {u'零':0, u'一':1, u'二':2, u'三':3, u'四':4,
- u'五':5, u'六':6, u'七':7, u'八':8, u'九':9,u'十':10,
- u'百':100, u'千':10 ** 3, u'万':10 ** 4,u'〇':0,
- u'壹':1, u'贰':2, u'叁':3, u'肆':4,u'伍':5,
- u'陆':6, u'柒':7, u'捌':8, u'玖':9,u'拾':10,
- u'佰':100, u'仟':10 ** 3, u'萬':10 ** 4,u'亿':10 ** 8, u'億':10 ** 8,
- u'幺': 1,u'两':2,
- u'0':0, u'1':1, u'2':2, u'3':3, u'4':4,
- u'5':5, u'6':6, u'7':7, u'8':8, u'9':9}
- def converion(temp, unit):
- intr = 0
- #print(temp, unit)
- temp_len = len(temp)
- if temp_len <= 2 and temp[0] == 10: #十到十九需要单独转换
- for i in temp:
- intr += i
- return intr * unit
- for i in range(temp_len):
- if temp[i] > 9 and temp[i-1] != 0:
- intr += temp[i] * temp[i-1]
- if temp[-1] < 10: intr += temp[-1]
- return intr * unit
- def split_unit(temp, unit):
- nu = []
- while True:
- if temp[0] != unit:
- nu.append(temp.pop(0))
- continue
- temp.pop(0)
- return converion(nu, unit)
- def onere(strarr):
- #一一四 ===>>> 114
- #四百三十六 ===>>> 436
- res = ''
- intr = 0
- com = re.compile('[十百千万]')
- if re.findall(com, strarr):
- temp = [ch_dict[i] for i in strarr] #列表666[6, 100, 6, 10, 6]
- if 10**8 in temp:
- intr += split_unit(temp, 10**8)
- if 10**4 in temp:
- intr += split_unit(temp, 10**4)
- if temp:
- intr += converion([ i for i in temp], 1)
- return str(intr)
- else:
- for i in strarr:
- res += str(ch_dict[i])
- return res
- ch_key = ''.join(ch_dict.keys())
- com = re.compile('第([' + ch_key + ']{1,20})[章|节]')
- file = [] #文件列表
- print('更改章节名中的中文数字为阿拉伯数字!')
- while True:
- try:
- # pa = input('请输入路径:')
- pa = r'D:\GIN\py\novel\biquge'
- os.chdir(pa)
- print('当前工作路径为:{}'.format(os.getcwd()))
- break
- except BaseException as err:
- print(err)
- continue
- for i,j,k in os.walk(pa):
- file = k
- j.clear()
- for i in file:
- res = re.findall(com,i)
- if res != [''] and res:
- news = i.replace(*res, onere(*res))
- print('{:<30}\n{:<30}\n'.format(i, news))
- # os.rename(i, news)
复制代码- 更改章节名中的中文数字为阿拉伯数字!
- 当前工作路径为:D:\GIN\py\novel\biquge
- 第一万亿两千三百六十五万三千六百二十八章.txt
- 第1000023653628章.txt
- 第一亿一千一百二十三万四千五百六十七章 - 副本.txt
- 第111234567章 - 副本.txt
- 第一千一百二十三万四千五百六十七章 - 副本 (9).txt
- 第11234567章 - 副本 (9).txt
- 第一千二百零三章 - 副本 (5).txt
- 第1203章 - 副本 (5).txt
- 第一百二十三万四千五百六十七章 - 副本 (8).txt
- 第1234567章 - 副本 (8).txt
- 第一百二十三章 - 副本 (4).txt
- 第123章 - 副本 (4).txt
- 第一百零二亿五千零一万零一千零三十八章 - 副本 - 副本.txt
- 第10250011038章 - 副本 - 副本.txt
- 第八章 - 副本 (3).txt
- 第8章 - 副本 (3).txt
- 第十一章 - 副本 (2).txt
- 第11章 - 副本 (2).txt
- 第十万零三千六百零九章 - 副本 (7).txt
- 第103609章 - 副本 (7).txt
- 请按任意键继续. . .
复制代码 |
|