code: Get contacts from previous parsing
This commit is contained in:
		| @ -30,29 +30,30 @@ rssi = 3 | ||||
|  | ||||
|  | ||||
| def main(args): | ||||
|   # All the contacts [tim, uid_a, uid_b]. | ||||
|   cont = [] | ||||
|   try: | ||||
|     print('Extracting %s... ' %(os.path.abspath(args.arc)), end='', flush=True) | ||||
|     with zipfile.ZipFile(args.arc, 'r') as arc: | ||||
|       print('[OK]') | ||||
|       with io.TextIOWrapper(arc.open(args.cont), newline='\n') as dat: | ||||
|         try: | ||||
|           print('Finding contacts... ', end='', flush=True) | ||||
|           # Get the contacts by skipping the header | ||||
|           cont_l = list(csv.reader(dat, delimiter=','))[hdr:] | ||||
|           # Check each contact | ||||
|           for c in cont_l: | ||||
|             if c[uid_b] != '-1' and c[rssi] != '0' and c[uid_b] != '-2' and c[uid_a] != c[uid_b]: | ||||
|               # Add valid contact | ||||
|               cont.append([c[tim], c[uid_a], c[uid_b]]) | ||||
|           print('[OK]') | ||||
|         except Exception as e: | ||||
|           print('[Error: %s]' %(e)) | ||||
|   except Exception as e: | ||||
|     print('[Error: %s]' %(e)) | ||||
|   # Save to results | ||||
|   lmdk_lib.save_data(args, np.array(cont), 'cont') | ||||
|   # Get contacts [tim, uid_a, uid_b] from previous parsing | ||||
|   cont = lmdk_lib.load_data(args, 'cont') | ||||
|   if cont.size == 0: | ||||
|     try: | ||||
|       print('Extracting %s... ' %(os.path.abspath(args.arc)), end='', flush=True) | ||||
|       with zipfile.ZipFile(args.arc, 'r') as arc: | ||||
|         print('[OK]') | ||||
|         with io.TextIOWrapper(arc.open(args.cont), newline='\n') as dat: | ||||
|           try: | ||||
|             print('Finding contacts... ', end='', flush=True) | ||||
|             # Get the contacts by skipping the header | ||||
|             cont_l = list(csv.reader(dat, delimiter=','))[hdr:] | ||||
|             # Check each contact | ||||
|             for c in cont_l: | ||||
|               if c[uid_b] != '-1' and c[rssi] != '0' and c[uid_b] != '-2' and c[uid_a] != c[uid_b]: | ||||
|                 # Add valid contact | ||||
|                 cont.append([c[tim], c[uid_a], c[uid_b]]) | ||||
|             print('[OK]') | ||||
|           except Exception as e: | ||||
|             print('[Error: %s]' %(e)) | ||||
|     except Exception as e: | ||||
|       print('[Error: %s]' %(e)) | ||||
|     # Save to results | ||||
|     lmdk_lib.save_data(args, np.array(cont), 'cont') | ||||
|  | ||||
|  | ||||
| ''' | ||||
|  | ||||
		Reference in New Issue
	
	Block a user