Update mac database build script and README.md
This commit is contained in:
parent
dea195045a
commit
caed213cb7
@ -8,5 +8,5 @@ The generated database is read performance optimized and tried to keep as small
|
|||||||
|
|
||||||
The final database will be named `mac-addresses.db`.
|
The final database will be named `mac-addresses.db`.
|
||||||
|
|
||||||
In nymea the `MacAddressDatabase` will search for this database file in `/usr/share/nymea/mac-addresses.db` and provides an asynch mechanism to get the company name for a given MAC address.
|
In nymea the `MacAddressDatabase` will search by default for this database file in `/usr/share/nymea/mac-addresses.db` and provides an asynch threaded mechanism to get the company name for a given MAC address.
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ downloadUrl='https://macaddress.io/database/macaddress.io-db.json'
|
|||||||
jsonDataFileName = 'macaddress.io-db.json'
|
jsonDataFileName = 'macaddress.io-db.json'
|
||||||
databaseFileName = 'mac-addresses.db'
|
databaseFileName = 'mac-addresses.db'
|
||||||
|
|
||||||
print('Downloading', jsonDataFileName, '...')
|
print('Downloading', downloadUrl, '...')
|
||||||
downloadRequest = requests.get(downloadUrl)
|
downloadRequest = requests.get(downloadUrl)
|
||||||
open(jsonDataFileName, 'wb').write(downloadRequest.content)
|
open(jsonDataFileName, 'wb').write(downloadRequest.content)
|
||||||
|
|
||||||
@ -55,9 +55,10 @@ for line in lines:
|
|||||||
jsonDataFile.close()
|
jsonDataFile.close()
|
||||||
|
|
||||||
if os.path.exists(databaseFileName):
|
if os.path.exists(databaseFileName):
|
||||||
print('Delete old db file and create a new one', databaseFileName)
|
print('Delete old db file', databaseFileName)
|
||||||
os.remove(databaseFileName)
|
os.remove(databaseFileName)
|
||||||
|
|
||||||
|
print('Build up database', databaseFileName)
|
||||||
connection = sqlite3.connect(databaseFileName)
|
connection = sqlite3.connect(databaseFileName)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute('CREATE TABLE companyNames (companyName TEXT PRIMARY KEY, UNIQUE(companyName));')
|
cursor.execute('CREATE TABLE companyNames (companyName TEXT PRIMARY KEY, UNIQUE(companyName));')
|
||||||
@ -78,7 +79,7 @@ for vendorInfo in sortedVendorHash:
|
|||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
# Insert all oui with reference to company name
|
# Insert all oui with reference to company name
|
||||||
print('Writing company names into database...')
|
print('Writing OUI into database with company name refference...')
|
||||||
# Sort by oui for good binary search in the db
|
# Sort by oui for good binary search in the db
|
||||||
sortedOuiHash = sorted(vendorInfoHash.items(), key=lambda x: x[0], reverse=False)
|
sortedOuiHash = sorted(vendorInfoHash.items(), key=lambda x: x[0], reverse=False)
|
||||||
ouiCount = 0
|
ouiCount = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user