Last active
June 14, 2022 10:17
-
-
Save companje/e7ff88aee91e9694308536dedf4b8fea to your computer and use it in GitHub Desktop.
Kadaster-zoekschil-conversie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import csv,os | |
from collections import defaultdict | |
rows = [ row for row in csv.DictReader(open("kadaster.csv")) ] | |
# "id","gemeente","arrondissement","dvd_nr","dvd_code","soort","leggerart","begin","eind","begino","eindo","invnr","reeksdeel","Sectie","pad","filenaam","naam1","naam2" | |
file_paths = defaultdict(list) | |
inv_nrs = defaultdict(dict) | |
for row in rows: | |
file_path = row['dvd_nr'] + row['pad'] + row["filenaam"] | |
file_paths[file_path].append(row) # row is any row | |
inv_nrs[row["invnr"].strip()][row["filenaam"]] = row #.append(row) | |
for inv_nr,rows in inv_nrs.items(): | |
source_folder = "/Volumes/archiefbestanden\\$/Kadaster/DVD\\'s/" | |
dest_folder = "scans/Kadaster-Scans/scans/NL-UtHUA_1294_" + inv_nr | |
if not os.path.isdir(dest_folder): | |
os.makedirs(dest_folder) | |
for filename,row in rows.items(): | |
source_file_path = source_folder + (row['dvd_nr'] + row['pad'] + row["filenaam"]).replace("\\","/") | |
dest_file_path = dest_folder + "/NL-UtHUA_1294_" + inv_nr + "_" + row["filenaam"] | |
print(source_file_path + "\t" + dest_file_path) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import csv,os,sys | |
from collections import defaultdict | |
from joblib import Parallel, delayed | |
from tqdm import tqdm | |
import shutil | |
from os.path import exists | |
def processRow(row): | |
src = row["src"] | |
dst = row["dst"] | |
if not exists(src.replace("\\","")): | |
print(f"ERROR src: {src} not found") | |
return | |
# create dst folder recursive | |
dest_folder = os.path.split(dst)[0] | |
if not os.path.isdir(dest_folder): | |
os.makedirs(dest_folder) | |
# check extension, convert TIF to JPG or just copy JPG | |
dst = dst.replace(".TIF",".JPG") | |
if exists(dst): | |
# print(f"SKIP {dst} already exists.") | |
return | |
filename, ext = os.path.splitext(dst) | |
if ext==".TIF": | |
os.system(f"convert {src} {dst} 2>>err.txt") | |
elif ext==".JPG": | |
src_without_backlash = src.replace("\\","") | |
shutil.copy2(src_without_backlash, dst) | |
else: | |
print(f"ERROR file format unsupported: {src} {dst}") | |
return | |
if not exists(dst): | |
print(f"ERROR dst: {dst} not found for src: {src}.") | |
# os.system(f"ffmpeg -i {src} {dst}") | |
# if not exists(dst): | |
# print(f"Error dst: {dst} STILL not found for src: {src}") | |
# else: | |
# print(f"Succesfully converted {src} to {dst} using FFMPEG") | |
rows = [ dict(row) for row in csv.DictReader(open("scans.tsv"), delimiter='\t', fieldnames=["src","dst"]) ] | |
results = Parallel(n_jobs=8)( | |
delayed(processRow)(row) | |
for row in tqdm(rows) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment