-
-
Save Tobey123/a818f7fa7a78b7df4c1376dba2db9ffb to your computer and use it in GitHub Desktop.
Revisions
-
naftulikay created this gist
Apr 30, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ #!/usr/bin/env python2.7 import argparse import os import qrcode import qrcode.image.pil import sqlite3 import sys import urllib class AuthenticatorAccount(object): def __init__(self, account_name, account_desc, secret): self.account_name = account_name self.account_desc = account_desc self.secret = secret def __repr__(self): return "AuthenticatorAccount@%s%s" % (hex(id(self))[2:], self.__dict__) def __main__(): parser = argparse.ArgumentParser() parser.add_argument("database", help="The SQLite database file.") args = parser.parse_args() if not os.path.isfile(args.database): sys.stderr.write("Unable to open %s.\n" % (args.database,)) sys.stderr.flush() sys.exit(1) conn = sqlite3.connect(args.database) conn.row_factory = sqlite3.Row cursor = conn.cursor() cursor.execute("SELECT * FROM accounts ORDER BY _id;") row = None while True: row = cursor.fetchone() if row is None: break account = AuthenticatorAccount(row['issuer'] or row['original_name'], row['email'], row['secret']) print """Saving "%s" to "qrcode-account-%02d.svg" """[:-1] % (account.account_desc, row['_id']) qr = qrcode.make("otpauth://totp/%s?secret=%s&issuer=%s" % (account.account_desc, account.secret, account.account_name), image_factory=qrcode.image.pil.PilImage) with open("qrcode-account-%02d.png" % (row['_id'],), "wb") as f: qr.save(f) if __name__ == "__main__": __main__()