Created
August 15, 2014 20:21
-
-
Save waleoyediran/d12e44fa60736bb26522 to your computer and use it in GitHub Desktop.
A custom encoder that helps serialize AppEngine's GeoPt and datetime objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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