Beispiel #1
0
def write_json(quoteResponseEntity):
    # First fetch the history of quotes
    quoteList = fetchQuoteResponse()
    # Now append the new quote
    quoteList = addQuoteToList(quoteList, quoteResponseEntity)
    # Now convert from quote entity list to JSON object
    quoteJSON = json.dumps(quoteList, ensure_ascii=False, default=lambda o: o.__dict__,
                           sort_keys=False, indent=4)
    with open(InitService.getQuoteFileLocation(), 'w+') as json_file:
        json_file.write(quoteJSON + '\n')
Beispiel #2
0
def fetchQuoteResponse():
    filename = initService.getQuoteFileLocation()
    if commonService.checkIfFileExists(filename):
        with open(filename) as json_file:
            JSONFromFile = json.load(json_file)
            # create list of quotes from json file
            quoteList = convertToList(JSONFromFile)
            return quoteList
    else:
        quoteList = []
        return quoteList