Extracting and cleaning up import script from Flask app