Пример #1
0
def process():

    print csv.list_dialects()
    dr = DictReader(
        codecs.open(
            FILENAME,
            "rb",
            "utf-8",
            "ignore"
        ),
        dialect='excel-tab'
    )
#   lines = open(FILENAME).readlines()
#   print len(lines)
#   print lines[0]
#   print lines[1]
    print dr.fieldnames

    waypoints = []
    for index, row in enumerate(dr):

        def fixup_row(key):
            t = row[key]
#           t = t.replace(chr(0x92), "'")
#           t = t.replace(chr(0x93), '"')
#           t = t.replace(chr(0x94), '"')
#           t = t.replace(chr(0x95), "-")
#           t = t.replace(chr(0xA0), " ")
            return t

        name = u"STL%03d" % index
#       name = fixup_row('Site')

#       Code = u"STL%03d" % index

        description = fixup_row('Site')

        latlon = row['GPS']
        if latlon:
            lat, lon = latlon.split()
        else:
            lat, lon = (0.0, 0.0)

        comment = u"; ".join([
            fixup_row('Location on Site'),
            fixup_row('First Screen'),
            fixup_row('Street Address'),
            fixup_row('City'),
            fixup_row('ST'),
            fixup_row('Zip'),
        ])

        waypoint = GSAKWaypoint(
            lat,
            lon,
            name=name,
            description=description,
            comment=comment,
            type="Geocache|Unknown Cache",
#           Code=Code
        )
#       print repr(waypoint)

        waypoints.append(waypoint)

    # create the gpx file
    gpx = GPX(waypoints)
    gpx.author = "Robert L. Oelschlaeger"
    gpx.email = "*****@*****.**"
    gpx.creator = "cake.py"
    gpx.description = "Location of St. Louis 250th Birthday Celebration cakes"

    # write it
    outfile = codecs.open(OUTFILENAME, "wb", "utf-8", "replace")
#   print dir(outfile)
    outfile.write(gpx.to_xml())
    outfile.close()

    # tell user
    print "output is in %s" % OUTFILENAME