import system
import csv
from docopt import docopt


def quad_tree(tx, ty, zoom):
    """
    Converts XYZ tile coordinates to Microsoft QuadTree
    http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    """
    quad_key = ''
    for i in range(zoom, 0, -1):
        digit = 0
        mask = 1 << (i-1)
        if (tx & mask) != 0:
            digit += 1
        if (ty & mask) != 0:
            digit += 2
        quad_key += str(digit)

    return quad_key


if __name__ == '__main__':
    args = docopt(__doc__, version='0.1')

    writer = csv.writer(system.out)
    with open(args['<list_file>'], "r") as file_handle:
        for line in file_handle:
            z, x, y = line.split('/')

            writer.writerow([
                line,
                quad_tree(int(x), int(y), int(z))]
            )

import sys
import csv
from docopt import docopt


def quad_tree(tx, ty, zoom):
    """
    Converts XYZ tile coordinates to Microsoft QuadTree
    http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    """
    quad_key = ''
    for i in range(zoom, 0, -1):
        digit = 0
        mask = 1 << (i-1)
        if (tx & mask) != 0:
            digit += 1
        if (ty & mask) != 0:
            digit += 2
        quad_key += str(digit)

    return quad_key


if __name__ == '__main__':
    args = docopt(__doc__, version='0.1')

    writer = csv.writer(sys.stdout, delimiter='\t')
    with open(args['<list_file>'], "r") as file_handle:
        for line in file_handle:
            z, x, y = line.split('/')

            writer.writerow([
                line.strip(),
                quad_tree(int(x), int(y), int(z))]
            )

Fix line endings in CSV and stdout typo
Fix line endings in CSV and stdout typo

- import system
+ import sys
  import csv
  from docopt import docopt
  
  
  def quad_tree(tx, ty, zoom):
      """
      Converts XYZ tile coordinates to Microsoft QuadTree
      http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
      """
      quad_key = ''
      for i in range(zoom, 0, -1):
          digit = 0
          mask = 1 << (i-1)
          if (tx & mask) != 0:
              digit += 1
          if (ty & mask) != 0:
              digit += 2
          quad_key += str(digit)
  
      return quad_key
  
  
  if __name__ == '__main__':
      args = docopt(__doc__, version='0.1')
  
-     writer = csv.writer(system.out)
+     writer = csv.writer(sys.stdout, delimiter='\t')
      with open(args['<list_file>'], "r") as file_handle:
          for line in file_handle:
              z, x, y = line.split('/')
  
              writer.writerow([
-                 line,
+                 line.strip(),
                  quad_tree(int(x), int(y), int(z))]
              )
  
Fix line endings in CSV and stdout typo
## Code Before:
import system
import csv
from docopt import docopt


def quad_tree(tx, ty, zoom):
    """
    Converts XYZ tile coordinates to Microsoft QuadTree
    http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    """
    quad_key = ''
    for i in range(zoom, 0, -1):
        digit = 0
        mask = 1 << (i-1)
        if (tx & mask) != 0:
            digit += 1
        if (ty & mask) != 0:
            digit += 2
        quad_key += str(digit)

    return quad_key


if __name__ == '__main__':
    args = docopt(__doc__, version='0.1')

    writer = csv.writer(system.out)
    with open(args['<list_file>'], "r") as file_handle:
        for line in file_handle:
            z, x, y = line.split('/')

            writer.writerow([
                line,
                quad_tree(int(x), int(y), int(z))]
            )

## Instruction:
Fix line endings in CSV and stdout typo
## Code After:
import sys
import csv
from docopt import docopt


def quad_tree(tx, ty, zoom):
    """
    Converts XYZ tile coordinates to Microsoft QuadTree
    http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    """
    quad_key = ''
    for i in range(zoom, 0, -1):
        digit = 0
        mask = 1 << (i-1)
        if (tx & mask) != 0:
            digit += 1
        if (ty & mask) != 0:
            digit += 2
        quad_key += str(digit)

    return quad_key


if __name__ == '__main__':
    args = docopt(__doc__, version='0.1')

    writer = csv.writer(sys.stdout, delimiter='\t')
    with open(args['<list_file>'], "r") as file_handle:
        for line in file_handle:
            z, x, y = line.split('/')

            writer.writerow([
                line.strip(),
                quad_tree(int(x), int(y), int(z))]
            )
