Ejemplo n.º 1
0
def cursorToArray(cursor, decrypted = False, probe = '', is_researcher=False, map_to_users=False):
	array = []
	for row in cursor:
		if 'timestamp' in row:
			row['timestamp'] = int(time.mktime(row['timestamp'].timetuple()))
		if 'timestamp_added' in row:
			row['timestamp_added'] = int(time.mktime(row['timestamp_added'].timetuple()))
		array.append(row)

	if 'ExperienceSamplingProbe' in probe:
		for doc in array:
			doc['answer'] = json.loads(base64.b64decode(doc['answer']))

	if 'EpidemicProbe' in probe:
		for doc in array:
			doc['data'] = json.loads(base64.b64decode(doc['data']))

	if 'BluetoothProbe' not in probe: return array
	if decrypted:
		anonymizer = Anonymizer()
		return anonymizer.deanonymizeDocument(array, probe)
	if is_researcher and map_to_users:
		deviceInventory = device_inventory.DeviceInventory()
		for doc in array:
			try:
				user_temp = deviceInventory.mapBtToUser(doc['bt_mac'], doc['timestamp'], use_mac_if_empty=False)
				if user_temp is not None:
					doc['scanned_user'] = user_temp
				else:
					doc['scanned_user'] = ''
			except KeyError: doc['scanned_user'] = ''
	return array