Skip to content

Instantly share code, notes, and snippets.

@holyjak
Created May 4, 2013 15:45
Show Gist options
  • Save holyjak/5517865 to your computer and use it in GitHub Desktop.
Save holyjak/5517865 to your computer and use it in GitHub Desktop.
Method Promiscuity Or The Case For Encapsulation: Do not expose more information and structure to the clients than necessary
...
# The client code
@my.route('/cleanjson/<collection>/')
def getcleanjson(collection):
cleandata = Cleanjson()
cleandata.get_mongojson(str(collection), "?s={'_id': 1}")
cleandata.parse_json(cleandata.rawjson)
return cleandata.cleanjson
# The API code
...
class Cleanjson:
...
def __init__(self):
self.cleanjson = []
...
def get_mongojson(self, collection, query):
self._make_requesturl(collection, query)
alldata = requests.get(self.request_url).json()
self.rawjson = alldata['rows']
def parse_json(self, datalist):
cleaned = [ { "date": datalist[i]['timestamp'], ... }
for i in range(len(datalist)) ]
self.cleanjson = json.dumps(cleaned)
return self.cleanjson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment