There is file with logs get list of ding ids that appear in this file

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 1. There is a file with logs, get list of ding ids that appear in this file and write to txt file,
# 2. get list mac,ding_id and write into csv file
def get_parameters_from_logs(input_file, parameter_1, parameter_2, output_file_txt, output_file_csv):
with open(input_file, "r") as f, open(output_file_txt, 'a') as file_parameters, open(output_file_csv, 'a') as double_parametres:
double_parametres.write(f'{parameter_1}, {parameter_2}\n')
line_count = 0
for row in f:
if line_count == 0:
line_count += 1
continue
line_count += 1
json_row = (row[1::].split('}')[0] + '}').replace('\""', '\"')
parsed_row = (json.loads(json_row))
if parameter_1 in parsed_row:
file_parameters.write(f'{parsed_row[parameter_1]}\n')
if parameter_2 in parsed_row:
double_parametres.write(f'{parsed_row[parameter_1]}, {parsed_row[parameter_2]}\n')
else:
double_parametres.write(f'{parsed_row[parameter_1]}, null\n')
get_parameters_from_logs('athena_logs.csv', 'ding_id', 'device_id', 'ding_ids.txt', 'ding_mac.csv')