Skip to content

Instantly share code, notes, and snippets.

@tfrisk-old
Created May 4, 2016 05:32
Show Gist options
  • Save tfrisk-old/c088b3a5d9442cf95f0898c96db881eb to your computer and use it in GitHub Desktop.
Save tfrisk-old/c088b3a5d9442cf95f0898c96db881eb to your computer and use it in GitHub Desktop.
Paradox database -> CSV converter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Paradox database -> CSV converter
# (C) 2016 Teemu Frisk / Pandia Ltd
# MIT License
#
# Usage:
# 1) Make sure this script and its related paradox.py files are in the same dir
# 2) Create directory for paradox files and copy the entire db there
# NOTE: Directory name will be appended to the generated csv file names
# 3) Run this script
# Example: $ python2 ./paradox-csv-converter.py
# NOTE: Python v2 is required, paradox.py won't work with Python 3
# 4) Enjoy your paradox database converted to CSV
# NOTE: Empty tables are ignored
# NOTE: Generated files may have encoding issues depending on source data
# paradox.py should be located in the same directory than this file
# Original source: https://gist.github.com/BertrandBordage/9892556
import paradox
import fnmatch
from os import path, walk, mkdir
from re import sub
from sys import exit, stdout
DEBUG=False # Show debug messages? True of False
def form_file_name(inputfile):
line = sub('\.\/','', inputfile) # Remove leading ''./'
line = sub(r'[\s\/]','_', line) # Convert special chars to '_' (spaces and '/')
return line.lower()
matches = []
# Walk current directory recursively and list all '.DB' files
# Original source: http://stackoverflow.com/a/2186565
for root, dirnames, filenames in walk('.'):
for filename in fnmatch.filter(filenames, '*.DB'):
matches.append(path.join(root, filename))
if not path.exists('./output/'):
mkdir('output')
all_files = len(matches)
csv_files = 0
ign_files = 0
for dbfile in matches:
outputfile = path.join('./output/' + form_file_name(dbfile) + '.csv')
if DEBUG:
print('dbfile: ' + dbfile)
print('outputfile: ' + outputfile)
try:
paradox.to_csv(dbfile, outputfile)
if not DEBUG:
stdout.write('.') # Print some progress indicator
csv_files += 1
except Exception as e:
if DEBUG:
print('Ignoring empty file [' + dbfile + ']')
ign_files += 1
print('\nParadox database processed, output csv files located in ./output/ directory.')
print('Total input files: ' + str(all_files))
print('Csv files generated: ' + str(csv_files))
print('Ignored: ' + str(ign_files))
@mzarg68
Copy link

mzarg68 commented Jul 17, 2023

I tried to install paradox library but it failed due to dependencies issues. How to solve it?
Which version of paradox must be installed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment