mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 08:34:00 +02:00
Import cards from JendaSAP list (nick UID list)
This commit is contained in:
parent
4256abe449
commit
9385a3749e
2 changed files with 62 additions and 8 deletions
|
@ -9,14 +9,10 @@ Give filename as first argument.
|
||||||
import sys
|
import sys
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def createTables(cursor):
|
||||||
if len(sys.argv) < 2:
|
"""Create DB tables in an empty database
|
||||||
print >> sys.stderr, "You must specify filename as arg1 where the DB is to be created"
|
@:param cursor cursor to sqlite DB
|
||||||
|
"""
|
||||||
filename = sys.argv[1]
|
|
||||||
conn = sqlite3.connect(filename)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("""CREATE TABLE authorized_uids(
|
cursor.execute("""CREATE TABLE authorized_uids(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
uid_hex TEXT,
|
uid_hex TEXT,
|
||||||
|
@ -33,5 +29,15 @@ if __name__ == "__main__":
|
||||||
uid_hex TEXT,
|
uid_hex TEXT,
|
||||||
nick TEXT)
|
nick TEXT)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print >> sys.stderr, "You must specify filename as arg1 where the DB is to be created"
|
||||||
|
|
||||||
|
filename = sys.argv[1]
|
||||||
|
conn = sqlite3.connect(filename)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
createTables(cursor)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
48
import_jendasap_cards.py
Executable file
48
import_jendasap_cards.py
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
from brmdoor_adduser import addUidAuth
|
||||||
|
from create_authenticator_db import createTables
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print "import_jendasap_cards.py <cards_from_sap.txt> <destination.sqlite>"
|
||||||
|
print "This will generate and COMPLETELY OVERWRITE the UID table in destination.sqlite"
|
||||||
|
print "This is useful for initial import, but for individual cards use brmdoor_adduser.py"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
destSqliteFname = sys.argv[2]
|
||||||
|
srcCardsFname = sys.argv[1]
|
||||||
|
nickUidList = []
|
||||||
|
with file(srcCardsFname) as f:
|
||||||
|
lineNo = 0
|
||||||
|
for line in f:
|
||||||
|
lineNo += 1
|
||||||
|
line = line.rstrip()
|
||||||
|
if line == "":
|
||||||
|
continue
|
||||||
|
parts = line.rstrip().split(" ")
|
||||||
|
if len(parts) != 2:
|
||||||
|
print "Skipping line %d, expected two parts - nick, uid, got: %s" % (lineNo, repr(parts))
|
||||||
|
continue
|
||||||
|
nickUidList.append(parts)
|
||||||
|
|
||||||
|
dbExists = os.path.isfile(destSqliteFname)
|
||||||
|
conn = sqlite3.connect(destSqliteFname)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
if dbExists:
|
||||||
|
cursor.execute("DELETE FROM authorized_uids")
|
||||||
|
else:
|
||||||
|
createTables(cursor)
|
||||||
|
|
||||||
|
for (nick, uid) in nickUidList:
|
||||||
|
addUidAuth(cursor, uid, nick)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
print "Converted %d nick-uid pairs into authorized_uids table" % (len(nickUidList),)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue