<commit_before>#!/usr/bin/env python

import argparse
import base64
import image
import json
import os.path
import qrcode


def get_json_from_path(path):
	with open(path, 'r') as f:
		json_data = f.read()
	return json_data

def json_to_uri(json_data):
	data = json.loads(json_data)
	uri = 'ss://' + base64.b64encode(data['server_password'][0][2] + ":" + data['server_password'][0][1] + "@" + data['server_password'][0][0])
	return uri

def generate_qrcode(uri, path):
	img = qrcode.make(uri)
	with open(path, 'w') as f:
		img.save(f)

def process(path):
	json_data = get_json_from_path(path)
	uri = json_to_uri(json_data)
	new_path = os.path.splitext(path)[0] + '.png'
	generate_qrcode(uri, new_path)

if __name__ == "__main__":
	parser = argparse.ArgumentParser(description='Shadowsocks JSON to QRCode')
	parser.add_argument('-s', '--source', dest='path', help='JSON config')
	args = parser.parse_args()

	path = args.path
	if os.path.isfile(path) and os.path.splitext(path)[1] == '.json':
		process(path)
	
	elif os.path.isdir(path):
		for root, dirs, files in os.walk(path):
		    for name in files:
		    	process(os.path.join(root, name))<commit_msg>Replace tab with space<commit_after>#!/usr/bin/env python

import argparse
import base64
import image
import json
import os.path
import qrcode


def get_json_from_path(path):
    with open(path, 'r') as f:
        json_data = f.read()
    return json_data

def json_to_uri(json_data):
    data = json.loads(json_data)
    uri = 'ss://' + base64.b64encode(data['server_password'][0][2] + ":" + data['server_password'][0][1] + "@" + data['server_password'][0][0])
    return uri

def generate_qrcode(uri, path):
    img = qrcode.make(uri)
    with open(path, 'w') as f:
        img.save(f)

def process(path):
    json_data = get_json_from_path(path)
    uri = json_to_uri(json_data)
    new_path = os.path.splitext(path)[0] + '.png'
    generate_qrcode(uri, new_path)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Shadowsocks JSON to QRCode')
    parser.add_argument('-s', '--source', dest='path', help='JSON config')
    args = parser.parse_args()

    path = args.path
    if os.path.isfile(path) and os.path.splitext(path)[1] == '.json':
        process(path)
    
    elif os.path.isdir(path):
        for root, dirs, files in os.walk(path):
            for name in files:
                process(os.path.join(root, name))
{'fraction_non_alphanumeric': 0.1550580431177446, 'fraction_numerical': 0.011608623548922056, 'mean_word_length': 3.9958592132505175, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '55306', 'n_tokens_mistral': 914, 'n_tokens_neox': 894, 'n_words': 192}