
import json
import os
from urlparse import urlparse
import zipfile 

import click

import adapters
from filters import BasicFilterer
import utils
import subprocess
 
@click.command()
@click.argument('file', type=click.Path(exists=True), required=True)
def vectorTiling(file):
    """ Function that creates vector tiles
    INPUT: geojson file generated by process.py 
    OUTPUT: mbtiles file containing vector tiles 
    """
    # Variables to change in production 
    path = '/Users/athissen/Documents/'

    min_zoom = 0 
    max_zoom = 14   
    paths_string = ''

    with open(file, 'rb') as f: 
        geojson = json.load(f)
    features = geojson['features']
    for item in features: 
        paths_string += path + item['properties']['path'] + ' '

    command = 'tippecanoe -f -o ' + 'result.mbtiles ' + paths_string + ' -z {} -Z {}'.format(max_zoom, min_zoom)
    subprocess.call(command,shell=True)

if __name__ == '__main__':

    vectorTiling()
    

import json
import click
import subprocess
import utils 
import os 
import logging
 
@click.command()
@click.argument('sources', type=click.Path(exists=True), required=True)
@click.argument('output', type=click.Path(exists=True), required=True)
@click.argument('min_zoom', default=5)
@click.argument('max_zoom', default=14)
def vectorTiling(sources, output, min_zoom, max_zoom):
    """ Function that creates vector tiles
    PARAMS: 
    	- sources : directory where the geojson file(s) are
    	- output : directory for the generated data 
    """
    files = []
    for file in utils.get_files(sources):
    	if not os.path.isdir(file): 
    		if file.split('.')[1] == 'geojson': 
    			files.append(file)

	logging.info("{} geojson found".format(len(files)))
	paths_string = ''

    for file in files: 
    	with open(file, 'rb') as f: 
        	geojson = json.load(f)
    	features = geojson['features']
    	for item in features: 
        	paths_string += item['properties']['path'] + ' '

    command = 'tippecanoe -f -o ' + output + '/result.mbtiles ' + paths_string + ' -z {} -Z {}'.format(max_zoom, min_zoom)
    subprocess.call(command,shell=True)

if __name__ == '__main__':

    vectorTiling()
    
Change of arguments, remove unused modules, source is now a directory