def test_type(self): ''' collect.flatdict: Tests for the resulting types of the collect function. ''' with open(self.file) as f: data = json.load(f) result = Flat.makeFlat(dictionary=data, delimiter='_') for record in result: self.assertIsNot(type(record), type({})) self.assertIsNot(type(record), type([]))
def collectData(url): ''' Collects data from a specific endpoint from OCHA CERF. ''' print('{bullet} Collecting data from: {url}'.format(bullet=item('bullet'), url=url)) r = requests.get(url) if _extension(url) == 'json': result = [] for record in r.json(): result.append(makeFlat(record)) else: result = [] tree = ElementTree.fromstring(r.content) for element in tree: record = XML.XmlDictConfig(element) result.append(makeFlat(record)) return result