Created
February 19, 2024 07:45
-
-
Save danielgospodinow/e744cf843a78a0317108967e1e9a220d to your computer and use it in GitHub Desktop.
Get CAN IDs present only in the second file, log also the number of their occurances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import collections | |
def extract_ids(filename): | |
with open(filename, "r") as file: | |
return [line.split()[2].split("#")[0] for line in file] | |
def count_ids(filename): | |
with open(filename, "r") as file: | |
return collections.Counter(line.split()[2].split("#")[0] for line in file) | |
if len(sys.argv) == 3: | |
# Files should be CAN log files recorded with the `candump` CLI. | |
file_without_command_ids = set(extract_ids(sys.argv[1])) | |
file_with_command_id_counts = count_ids(sys.argv[2]) | |
for id, count in file_with_command_id_counts.items(): | |
if id not in file_without_command_ids: | |
print( | |
f"ID {id} is present only in the second file and occurs {count} times." | |
) | |
else: | |
print("Please provide two file names as arguments.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment