Created
April 8, 2017 22:31
-
-
Save YoukaiCat/402696233a0ec9fa3600b31bc1e4c159 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
# | |
# Copyright 2017 Vladislav Mileshkin | |
# Copyright 2015 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de> | |
# Copyright 2015 Daniel Gultsch <daniel@cgultsch.de> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
import os | |
import qrcode | |
# get_qrcode function from Gajim OMEMO plugin | |
def get_qrcode(jid, sid, fingerprint): | |
file_name = 'omemo_{}_{}.png'.format(jid, sid) | |
path = os.path.join('.', file_name) | |
ver_string = 'xmpp:{}?omemo-sid-{}={}'.format(jid, sid, fingerprint) | |
print(ver_string) | |
if os.path.exists(path): | |
return path | |
qr = qrcode.QRCode(version=None, error_correction=2, box_size=4, border=1) | |
qr.add_data(ver_string) | |
qr.make(fit=True) | |
img = qr.make_image() | |
img.save(path) | |
return path | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser(description='Create QRCode for Conversations') | |
parser.add_argument('-j', '--jid', metavar='jid', required=True, | |
dest='jid', type=str, help='Jabber ID, e.g. example@jabber.com') | |
parser.add_argument('-s', '--sid', metavar='deviceid', required=True, | |
dest='sid', type=str, help='Device ID, e.g. 1234567890') | |
parser.add_argument('-f', '--fpr', metavar='fingerprint', required=True, nargs='+', | |
dest='fpr', type=str, help='Fingerprint, e.g. 010101010 (x 8)') | |
args = parser.parse_args() | |
print(get_qrcode(args.jid.lower(), args.sid, "".join(args.fpr).lower())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment