#! /usr/bin/env python
import sys
import csv
import os.path
import datetime
from vectortile import TileBounds

MAX_ZOOM=15

with open(sys.argv[1]) as infile:
    infile = csv.DictReader(infile)
    with open(sys.argv[2], "w") as outfile:
        outfile = csv.DictWriter(outfile, infile.fieldnames + ['gridcode'], 'ignore')
        outfile.writeheader()
        for row in infile:
            row['gridcode'] = str(TileBounds.from_point(lon=float(row['longitude']), lat=float(row['latitude']), zoom_level=MAX_ZOOM))
            outfile.writerow(row)


