Skip to content

Instantly share code, notes, and snippets.

@Gabriellpweb
Created February 19, 2016 18:02
Show Gist options
  • Save Gabriellpweb/cf16c6a46516a88f58dc to your computer and use it in GitHub Desktop.
Save Gabriellpweb/cf16c6a46516a88f58dc to your computer and use it in GitHub Desktop.
Copy a list of files to a list of possible files that filename matches with 75% of assert rate.
#!/usr/bin/env python
from __future__ import print_function
import math
import difflib
import shutil
import os.path
recovered = 'tofiles.txt'
original = 'fromfiles.txt'
found = 'found.txt'
src_image_path = '/home/usr/src'
dest_image_path = '/home/usr/dst'
with open(recovered) as rfile:
for rline in rfile:
try:
rlength = int(math.ceil((len(rline) / 2)))
rtxt_teste = rline[:rlength]
if rtxt_teste <> '':
with open(original) as ofile:
for line in ofile:
try:
copy = False
if rline in line:
#print('(%s) => %s match %s' % (rline, rtxt_teste, line))
copy = True
elif difflib.SequenceMatcher(None, rline, line).ratio() > 0.75:
#print('(%s) => %s fuzz match %s' % (rline, rtxt_teste, line))
copy = True
elif rtxt_teste in line:
#print('(%s) => %s match %s' % (rline, rtxt_teste, line))
copy = True
if copy:
src_image = (src_image_path + rline).replace('\n', '')
dst_image = (dest_image_path + line).replace('\n', '')
shutil.copy2(src_image, dst_image)
print ('[%s] from %s to %s' % (os.path.isfile(src_image), src_image, dst_image))
break
except:
print('ops2')
raise
except:
print('ops1')
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment