Skip to content

Instantly share code, notes, and snippets.

@uncletomiwa
Forked from waleoyediran/geodateencoder.py
Created August 16, 2014 06:07
Show Gist options
  • Save uncletomiwa/be10759d3b39958c8ce5 to your computer and use it in GitHub Desktop.
Save uncletomiwa/be10759d3b39958c8ce5 to your computer and use it in GitHub Desktop.
import json
import datetime
from time import mktime
from google.appengine.ext import ndb
__author__ = 'oyewale'
class GeoDateEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return int(mktime(obj.timetuple()))
elif isinstance(obj, ndb.GeoPt):
return {'lat': obj.lat, 'lon': obj.lon}
return json.JSONEncoder.default(self, obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment