# -*- coding: utf-8 -*-
# replacing spaces with dots
import sys, os
path = os.getcwd()
def work():
new_List = [] #
old_List = []
new_List.clear() #
old_List.clear()
print('')
FN = input('Введите имя файла:')
fn1=os.path.join(path, FN)
base=os.path.splitext(FN)[0]
fb2_file=open(fn1,'r')
old_List=fb2_file.readlines()
fb2_file.close()
n = 0
for item in old_List:
, , n += 1
, , s='|'+item
, , s=s.replace('\t',' ')
, , s=s.replace('| ','| . .')
, , s=s.replace(' ',' . .')
, , s = "{0:2d}{1:s}".format(n,s)
, , new_List.append(s)
fn2=os.path.join(path, base)+".txt"
new_file=open(fn2,'w')
for item in new_List:
, , new_file.write(item)
new_file.close()
print('Done')
while True:
work() # Exit => Ctrl + C
_my_zip.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Упаковка файлов fb2 в архивы zip
import sys, os
import zipfile
co = 0
def parse_file(FileName):
, ,global co
, ,fn = os.path.basename(FileName)
# , ,print fn+'.zip'
, ,z = zipfile.ZipFile(fn+'.zip', 'w', zipfile.ZIP_DEFLATED) # Создание нового архива
, ,z.write(fn)
, ,z.close()
, ,os.remove(FileName)
, ,co += 1
def parse_dir(fn):
, , , ,m = fn.split('.')[-1]
# , , , ,print fn
, , , ,if (m == 'fb2'):
, , , , , ,parse_file(fn)
, , , , , ,
, , , , , ,
path = os.getcwd()
files = os.listdir(path)
for file in files:
# , , , ,print (os.path.join(path, file))
, , , ,parse_dir(os.path.join(path, file))
print ('Zip => ' + str(co))
print ('Done!')
5
main_ok.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
import xml.dom.minidom
import zipfile
import shutil
# form 21.05.2021
#sys.path.append("/work/Python/modules/s")
#--------------------------------------------------
#from m_list import Books
Books = []
def FindValue(s1, s2):
global Books
# L1 = []
maxW = len(Books)
L1 = [s1, s2]
if maxW == 0:
, , Books.append(L1)