<commit_before># -*- encoding: utf-8 -*-

import os
import json
import base64
from Crypto.Cipher import AES
from urllib2 import urlopen
import mysql.connector


def decrypt(edata, password):
    edata = base64.urlsafe_b64decode(edata)
    aes = AES.new(password, AES.MODE_CBC, password[:16])
    return unpad(aes.decrypt(edata))

def unpad(padded):
    pad = ord(padded[-1])
    return padded[:-pad]

def main():
    dir = os.path.dirname(os.path.abspath(__file__))
    with open(dir + '/settings.json') as settings_file:
        settings = json.load(settings_file)
        password = settings['password']
        server_address = settings['server_address']

        url = server_address + '/organization/role_aliases.json'

        contents = urlopen(url).read()
        decoded = decrypt(contents, password)
        data = json.loads(decoded)

        domain_id = settings["domain_id"].encode('utf-8')
        connection = mysql.connector.connect(
            user=settings["database_user"].encode('utf-8'),
            password=settings["database_password"].encode('<PASSWORD>'),
            host=settings["database_host"].encode('utf-8'),
            database=settings["database"].encode('utf-8'),
        )
        cursor = connection.cursor(buffered=True)

        for role_email, user_emails in data.items():
            source = role_email
            destination = " ".join(user_emails)
            query = "select destination from virtual_aliases where source=%s and domain_id=%s"
            cursor.execute(query, (source, domain_id))
            if cursor.rowcount == 0:
                print "will insert", source, destination
                query = "insert into virtual_aliases set destination=%s where source=%s and domain_id=%"
                cursor.execute(query, (destination, source, domain_id))
            elif cursor.rowcount == 1:
                for (db_destination,) in cursor:
                    if destination != db_destination:
                        print "different, will update", source, db_destination, "→ ", destination
                        query = "update virtual_aliases set destination=%s where source=%s and domain_id=%s"
                        cursor.execute(query, (destination, source, domain_id))
            else:
                print("error", cursor.rowcount, "is too high")

        connection.commit()
        cursor.close()
        connection.close()
        

if __name__ == '__main__':
    main()<commit_msg>Whitespace<commit_after># -*- encoding: utf-8 -*-

import os
import json
import base64
from Crypto.Cipher import AES
from urllib2 import urlopen
import mysql.connector


def decrypt(edata, password):
    edata = base64.urlsafe_b64decode(edata)
    aes = AES.new(password, AES.MODE_CBC, password[:16])
    return unpad(aes.decrypt(edata))

def unpad(padded):
    pad = ord(padded[-1])
    return padded[:-pad]

def main():
    dir = os.path.dirname(os.path.abspath(__file__))
    with open(dir + '/settings.json') as settings_file:
        settings = json.load(settings_file)
        password = settings['password']
        server_address = settings['server_address']

        url = server_address + '/organization/role_aliases.json'

        contents = urlopen(url).read()
        decoded = decrypt(contents, password)
        data = json.loads(decoded)

        domain_id = settings["domain_id"].encode('utf-8')
        connection = mysql.connector.connect(
            user=settings["database_user"].encode('utf-8'),
            password=settings["database_password"].encode('<PASSWORD>'),
            host=settings["database_host"].encode('utf-8'),
            database=settings["database"].encode('utf-8'),
        )
        cursor = connection.cursor(buffered=True)

        for role_email, user_emails in data.items():
            source = role_email
            destination = " ".join(user_emails)
            query = "select destination from virtual_aliases where source=%s and domain_id=%s"
            cursor.execute(query, (source, domain_id))
            if cursor.rowcount == 0:
                print "will insert", source, destination
                query = "insert into virtual_aliases set destination=%s where source=%s and domain_id=%"
                cursor.execute(query, (destination, source, domain_id))
            elif cursor.rowcount == 1:
                for (db_destination,) in cursor:
                    if destination != db_destination:
                        print "different, will update", source, db_destination, "→ ", destination
                        query = "update virtual_aliases set destination=%s where source=%s and domain_id=%s"
                        cursor.execute(query, (destination, source, domain_id))
            else:
                print("error", cursor.rowcount, "is too high")

        connection.commit()
        cursor.close()
        connection.close()


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.11791014433828013, 'fraction_numerical': 0.006911973978450905, 'mean_word_length': 2.477031802120141, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1974482', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1318, 'n_words': 315}