clean up directory structure
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import argparse
|
||||
from progress import bar
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
print('Python imaging not installed\nRun "pip install Pillow" to install')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def img2tables(img_file, width=None, height=None) -> str:
|
||||
img = Image.open(img_file).convert('RGB')
|
||||
if height and width:
|
||||
img = img.resize((width, height), Image.ANTIALIAS)
|
||||
size_x, size_y = img.size
|
||||
|
||||
html = """
|
||||
<html>
|
||||
<body bgcolor=000000>
|
||||
<table border=0 cellpadding=0 cellspacing=0>
|
||||
"""
|
||||
for row in bar.ChargingBar('Running').iter(range(size_y)):
|
||||
html += '<tr height=1>'
|
||||
for col in range(size_x):
|
||||
r = img.getpixel((col, row))[0]
|
||||
g = img.getpixel((col, row))[1]
|
||||
b = img.getpixel((col, row))[2]
|
||||
html += f'<td width=1 bgcolor=#{r:02x}{g:02x}{b:02x}></td>'
|
||||
html += '</tr>'
|
||||
html += """
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def parse_args():
|
||||
def parse_size(value):
|
||||
if not re.compile(r'[0-9]+x[0-9]+').match(value):
|
||||
raise argparse.ArgumentTypeError('Invalid resizing argument.')
|
||||
width, height, *_ = value.split('x')
|
||||
return int(width), int(height)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Convert an image file to HTML tables'
|
||||
)
|
||||
parser.add_argument(
|
||||
'image_path',
|
||||
type=str,
|
||||
help='The image file to convert.')
|
||||
parser.add_argument(
|
||||
'-r',
|
||||
metavar='size',
|
||||
dest='size',
|
||||
type=parse_size,
|
||||
help='Resize the image. Example "200x100"')
|
||||
parser.add_argument(
|
||||
'-o',
|
||||
metavar='output_path',
|
||||
dest='output_path',
|
||||
type=str,
|
||||
help='Output file name.')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
|
||||
size = (None, None)
|
||||
if args.size:
|
||||
size = args.size
|
||||
|
||||
print(f'Starting conversion of "{args.image_path}"')
|
||||
try:
|
||||
html = img2tables(args.image_path, *size)
|
||||
except KeyboardInterrupt:
|
||||
print('Conversion aborted.')
|
||||
sys.exit(0)
|
||||
|
||||
out = os.path.splitext(args.image_path)[0] + '.html'
|
||||
|
||||
if args.output_path:
|
||||
out = args.output_path
|
||||
print(f'Saving to file "{out}"')
|
||||
with open(out, "w") as f:
|
||||
f.write(html)
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
FILES="$@"
|
||||
for i in $FILES
|
||||
do
|
||||
echo "Prcoessing image $i ..."
|
||||
/usr/bin/convert -thumbnail 200 $i "${i%.JPG}-thumb.JPG"
|
||||
done
|
||||
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
import csv
|
||||
import re
|
||||
|
||||
file_in = sys.argv[1]
|
||||
ext_match = re.compile(re.escape('.csv'), re.IGNORECASE)
|
||||
file_out = ext_match.sub('-converted.csv', file_in)
|
||||
fieldnames = ['date', 'payment', 'info', 'payee', 'memo', 'amount', 'category', 'tags']
|
||||
print(f'Writing to {file_out}')
|
||||
with open(file_out, mode='w') as csv_out:
|
||||
with open(file_in) as csv_file:
|
||||
|
||||
writer = csv.DictWriter(csv_out, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
|
||||
reader = csv.reader(csv_file, delimiter=';')
|
||||
line_count = 0
|
||||
for row in reader:
|
||||
if line_count == 0:
|
||||
line_count += 1
|
||||
continue
|
||||
try:
|
||||
out_row = {
|
||||
'date': row[1],
|
||||
'payment': 0,
|
||||
'info': '',
|
||||
'payee': row[11],
|
||||
'memo': row[4],
|
||||
'amount': row[14],
|
||||
'category': '',
|
||||
'tags': ''
|
||||
}
|
||||
writer.writerow(out_row)
|
||||
print(f'Converted: {out_row}')
|
||||
line_count += 1
|
||||
except:
|
||||
e = sys.exc_info()[0]
|
||||
print(e)
|
||||
print(f'Processed {line_count} lines.')
|
||||
Reference in New Issue
Block a user