forked from DeaconDesperado/swfty-share
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_encoder.py
More file actions
29 lines (23 loc) · 719 Bytes
/
json_encoder.py
File metadata and controls
29 lines (23 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="mark"
__date__ ="$Nov 30, 2011 8:50:18 AM$"
from datetime import datetime
import json
from models.story import Story
try:
from pymongo.objectid import ObjectId
except ImportError:
from bson.objectid import ObjectId
class Encoder(json.JSONEncoder):
def default(self,obj):
if isinstance(obj,set):
return list(obj)
elif isinstance(obj,datetime):
fmt = '%Y-%m-%dT%H:%M:%SZ'
return obj.strftime(fmt)
elif isinstance(obj,ObjectId):
return str(obj)
elif isinstance(obj,Story):
return dict(obj)