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

from round import client
from gem_migrator.nacl_passphrasebox import NaclPassphraseBox
from coinop.passphrasebox import PassphraseBox
from sys import argv
from argparse import ArgumentParser
from getpass import getpass


parser = ArgumentParser(
    description=("A simple utility for migrating Gem application wallets. You "
                 "can find the required parameters in the Gem web console at: "
                 "https://developers.gem.co"))
parser.add_argument('api_token', help="Your api_token")
parser.add_argument('admin_token', help="Your admin_token")
parser.add_argument('totp_secret', help="Your totp_secret")

if __name__ == '__main__':
    args = parser.parse_args()

    cli = client()

    app = cli.authenticate_application(api_token=args.api_token,
                                       admin_token=args.admin_token)
    app.set_totp(args.totp_secret)

    for w in app.wallets:
        if w.primary_private_seed['iv']:
            continue
        print("Enter your passphrase for {}: ".format(w.name))
        try:
            passphrase = getpass()
            seed = NaclPassphraseBox.decrypt(passphrase, w.primary_private_seed)
            encrypted_seed = PassphraseBox.encrypt(passphrase, seed)
            w.with_mfa(app.get_mfa()).update(
                {'name': w.name,
                 'primary_private_seed': encrypted_seed})
            print("{} updated successfully!".format(w.name))
        except Exception as e:
            print(e.message)
            print("Looks like something went wrong. Check your passphrase and "
                  "try running this utility again.")
            break

    print "Done!"<commit_msg>tweaks/typos/python3 compatibility<commit_after>#! /usr/bin/env python

from future.utils import iteritems
from round import client
from gem_migrator.nacl_passphrasebox import NaclPassphraseBox
from coinop.passphrasebox import PassphraseBox
from sys import argv
from argparse import ArgumentParser
from getpass import getpass


parser = ArgumentParser(
    description=("A simple utility for migrating Gem application wallets. You "
                 "can find the required parameters in the Gem web console at: "
                 "https://developers.gem.co"))
parser.add_argument('api_token', help="Your api_token")
parser.add_argument('admin_token', help="Your admin_token")
parser.add_argument('totp_secret', help="Your totp_secret")

if __name__ == '__main__':
    args = parser.parse_args()

    cli = client('http://localhost:8999')

    app = cli.authenticate_application(api_token=args.api_token,
                                       admin_token=args.admin_token)
    app.set_totp(args.totp_secret)

    for w in app.wallets.values():
        print(type(w))
        print(w)
        if w.primary_private_seed['iv']:
            continue
        print("Enter your passphrase for {}".format(w.name))
        try:
            passphrase = getpass("passphrase: ")
            seed = NaclPassphraseBox.decrypt(passphrase, w.primary_private_seed)
            encrypted_seed = PassphraseBox.encrypt(passphrase, seed)
            w.with_mfa(app.get_mfa()).resource.update(
                {'name': w.name,
                 'primary_private_seed': encrypted_seed})
            print("{} updated successfully!".format(w.name))
        except Exception as e:
            print(e.message)
            print("Looks like something went wrong. Check your passphrase and "
                  "try running this utility again.")
            break

    print("Done!")
{'fraction_non_alphanumeric': 0.09629421673217294, 'fraction_numerical': 0.001403705783267827, 'mean_word_length': 2.6960580912863072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7163927', 'n_tokens_mistral': 1003, 'n_tokens_neox': 976, 'n_words': 247}