from pymongo import MongoClient from bson.objectid import ObjectId class db(): def __init__(self): self.client = MongoClient('localhost', 27017) self.col=self.client.alexis["sources"] def jsonable(self, el): if el is None or "_id" not in el: return el el["_id"]=str(el["_id"]) return el def sources(self,id=None): if id is None: return [ self.jsonable(p) for p in self.col.find() ] ret=self.col.find_one({"_id":ObjectId(id)}) return self.jsonable(ret) def rss_sources(self): return [ p for p in self.col.find({"rss":1}) ]