К книге
Приложение к «Python в библиотеке»Arch. 10. same_fb2.py
59%
Arch. 10. same_fb2.py
20

#!/bin/env python

# -*- coding: utf-8 -*-

import sys, os

from m_list import FindValue, PrintList, Books

list = []

def fb2zip(pa):

, ,p = pa.split('/')

, ,FindValue(p[-1],pa)

# -----------------

def GetListFiles(PathForWork):

, ,global list

, ,for file in os.listdir(PathForWork):

, , , ,path = os.path.join(PathForWork, file)

, , , ,ex = path.split('.')

, , , ,if not os.path.isdir(path): #

, , , , , ,if ex[-1].lower() == 'fb2':

, , , , , , , ,fb2zip(path)

, , , , , ,else:

, , , , , , , ,e = ex[-2]+ex[-1]

, , , , , , , ,if e.lower() == 'fb2zip':

, , , , , , , , , ,fb2zip(path)

, , , ,else: #

, , , , , ,GetListFiles(path) #

# -----------------

def CompareList():

, ,OldFile = ''

, ,OldPath = ''

, ,flag = False

, ,for it in Books:

, , , ,if (it[0] == OldFile):

, , , , , ,if not flag :

, , , , , , , ,flag = True

, , , , , , , ,list.append(OldPath)

, , , , , ,list.append(it[1])

, , , ,else:

, , , , , ,if flag:

, , , , , , , ,flag = False

, , , , , , , ,list.append('------------')

, , , , , ,OldFile = it[0]

, , , , , ,OldPath = it[1]

# -----------------

# Main:

Mpath = os.getcwd()

GetListFiles(Mpath)

CompareList()

if len(list) == 0:

, ,print('Дубликатов нет.')

else:

, ,new_file = open(fn2,'w')

, ,for i in list: #

, , , ,new_file.write(i)

, , , ,print i

, ,print 'Done!'

, ,new_file.close

Предыдущая главаГлава 20 из 34Следующая глава