<commit_before>
"""A simple single thread WeChat client."""

import click
import sys
import time

from logging import config, getLogger

from pywxclient.core import Session, SyncClient, parse_message
from pywxclient.core.exception import (
    WaitScanQRCode, RequestError, APIResponseError, SessionExpiredError,
    AuthorizeTimeout, UnsupportedMessage)


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': (
                '[%(levelname)1.1s %(asctime)s %(process)d %(module)s:'
                '%(lineno)d] %(message)s')
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {
    },
    'handlers': {
        'console_log': {
            'level': 'DEBUG',
            'filters': [],
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'client': {
            'handlers': ['console_log'],
            'level': 'DEBUG'
        },
        'pywxclient': {
            'handlers': ['console_log'],
            'level': 'DEBUG'
        }
    }
}


def sync_session(client):
    """Sync wechat session."""
    client_log = getLogger('client')
    authorize_url = client.open_authorize_url()

    client_log.info('Authorization url: {}'.format(authorize_url))

    while True:
        try:
            authorize_success = client.authorize()
        except WaitScanQRCode:
            continue
        except AuthorizeTimeout:
            client_log.warn('Waiting for authorization timeout.')
            sys.exit(0)

        if authorize_success:
            break

        client_log.info('Waiting for authorization...')
        time.sleep(2)

    client.login()
    client_log.info('Login success...')

    while True:
        try:
            sync_ret = client.sync_check()
            if sync_ret != 0:
                msgs = client.sync_message()
                for msg in msgs['AddMsgList']:
                    try:
                        msg_obj = parse_message(msg)
                    except UnsupportedMessage:
                        client_log.info('unsupported message %s', msg)
                        continue
                    else:
                        client_log.info(
                            'receive message %s, %s', msg_obj, msg_obj.message)

                client.flush_sync_key()
        except (RequestError, APIResponseError):
            client_log.info('api error.')
        except SessionExpiredError:
            client_log.warn('wechat session is expired....')
            break


@click.group()
def main():
    """Command entry."""<commit_msg>Change deprecated function warn to warning.<commit_after>
"""A simple single thread WeChat client."""

import click
import sys
import time

from logging import config, getLogger

from pywxclient.core import Session, SyncClient, parse_message
from pywxclient.core.exception import (
    WaitScanQRCode, RequestError, APIResponseError, SessionExpiredError,
    AuthorizeTimeout, UnsupportedMessage)


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': (
                '[%(levelname)1.1s %(asctime)s %(process)d %(module)s:'
                '%(lineno)d] %(message)s')
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {
    },
    'handlers': {
        'console_log': {
            'level': 'DEBUG',
            'filters': [],
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'client': {
            'handlers': ['console_log'],
            'level': 'DEBUG'
        },
        'pywxclient': {
            'handlers': ['console_log'],
            'level': 'DEBUG'
        }
    }
}


def sync_session(client):
    """Sync wechat session."""
    client_log = getLogger('client')
    authorize_url = client.open_authorize_url()

    client_log.info('Authorization url: {}'.format(authorize_url))

    while True:
        try:
            authorize_success = client.authorize()
        except WaitScanQRCode:
            continue
        except AuthorizeTimeout:
            client_log.warning('Waiting for authorization timeout.')
            sys.exit(0)

        if authorize_success:
            break

        client_log.info('Waiting for authorization...')
        time.sleep(2)

    client.login()
    client_log.info('Login success...')

    while True:
        try:
            sync_ret = client.sync_check()
            if sync_ret != 0:
                msgs = client.sync_message()
                for msg in msgs['AddMsgList']:
                    try:
                        msg_obj = parse_message(msg)
                    except UnsupportedMessage:
                        client_log.info('unsupported message %s', msg)
                        continue
                    else:
                        client_log.info(
                            'receive message %s, %s', msg_obj, msg_obj.message)

                client.flush_sync_key()
        except (RequestError, APIResponseError):
            client_log.info('api error.')
        except SessionExpiredError:
            client_log.warning('wechat session is expired....')
            break


@click.group()
def main():
    """Command entry."""
{'fraction_non_alphanumeric': 0.12063318777292577, 'fraction_numerical': 0.002183406113537118, 'mean_word_length': 1.741645885286783, 'pattern_counts': {'":': 0, '<': 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': '3903373', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1497, 'n_words': 326}