-
-
Save lichang333/1df1bd631a62026703746eb8211804ca to your computer and use it in GitHub Desktop.
Generate QR code from Shadowsocks config json
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 python | |
from __future__ import print_function | |
from sh import qrencode | |
import base64 | |
import json | |
import sys | |
def main(): | |
if len(sys.argv) < 2: | |
print("Not enough arguments", file=sys.stderr) | |
exit(1) | |
try: | |
args = json.load(open(sys.argv[1])) | |
result = "%(method)s:%(password)s@%(server)s:%(server_port)d" % args | |
result = base64.b64encode(result.encode('ascii')).decode('ascii') | |
result = "ss://" + result | |
qrencode('-t', 'utf8', result) | |
except IOError as ex: | |
print("Error opening file:", ex.strerror, file=sys.stderr) | |
except ValueError as ex: | |
print("Invalid file content:", ex.strerror, file=sys.stderr) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment