Created
May 4, 2013 15:45
-
-
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
This file contains 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
... | |
# 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 |
This file contains 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
# 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