Skip to content

Instantly share code, notes, and snippets.

@lichang333
Created December 11, 2019 04:24
Show Gist options
  • Save lichang333/1df1bd631a62026703746eb8211804ca to your computer and use it in GitHub Desktop.
Save lichang333/1df1bd631a62026703746eb8211804ca to your computer and use it in GitHub Desktop.
Generate QR code from Shadowsocks config json
#!/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