• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# This script generates a python-syntax list of dictionary entries for the
17# company IDs listed at: https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/
18# The input to this script is the CSV file that can be obtained at that URL
19# -----------------------------------------------------------------------------
20
21# -----------------------------------------------------------------------------
22# Imports
23# -----------------------------------------------------------------------------
24import sys
25import csv
26
27# -----------------------------------------------------------------------------
28with open(sys.argv[1], newline='') as csvfile:
29    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
30    lines = []
31    for row in reader:
32        if len(row) == 3 and row[1].startswith('0x'):
33            company_id = row[1]
34            company_name = row[2]
35            escaped_company_name = company_name.replace('"', '\\"')
36            lines.append(f'    {company_id}: "{escaped_company_name}"')
37
38    print(',\n'.join(reversed(lines)))
39