<commit_before># -*- coding: utf-8 -*-
import calendar
import datetime
import logging
import os
import shutil
import subprocess
import time

from maidchan.constant import Constants


# TODO: Refactor send_text_message and send_image
def send_text_message(access_token, recipient_id, text, passive=False):
    """
    Note: MESSAGE_TAG is introduced to circumvent 24+1h window limit
    """
    escaped_text = text.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
    args = [
        'curl',
        '-F',
        'recipient={"id":"%s"}' % recipient_id,
        '-F',
        'message={"text": "%s"}' % escaped_text
    ]
    if passive:
        args.append('-F')
        args.append('messaging_type=MESSAGE_TAG')
        args.append('-F')
        args.append('tag=NON_PROMOTIONAL_SUBSCRIPTION')
    else:
        args.append('-F')
        args.append('messaging_type=RESPONSE')
    args.append(
        'https://graph.facebook.com/v2.7/me/messages?access_token={}'.format(
            access_token
        )
    )
    # Execute
    p = subprocess.Popen(args, stdout=subprocess.PIPE, shell=False)
    (output, err) = p.communicate()
    if err:
        logging.error(err)


def send_image(access_token, recipient_id, image_path,
               image_type, passive=False):
    """
    Note: MESSAGE_TAG is introduced to circumvent 24+1h window limit
    """
    args = [
        'curl',
        '-F',
        'recipient={"id":"%s"}' % recipient_id,
        '-F',
        'message={"attachment":{"type":"image", "payload":{}}}',
        '-F',
        'filedata=@{};type={}'.format(image_path, image_type)
    ]
    if passive:
        args.append('-F')
        args.append('messaging_type=MESSAGE_TAG')
        args.append('-F')
        args.append('tag=NON_PROMOTIONAL_SUBSCRIPTION')
    else:
        args.append('-F')
        args.append('messaging_type=RESPONSE')
    args.append(
        'https://graph.facebook.com/v2.7/me/messages?access_token={}'.format(<commit_msg>Use API v2.8<commit_after># -*- coding: utf-8 -*-
import calendar
import datetime
import logging
import os
import shutil
import subprocess
import time

from maidchan.constant import Constants


# TODO: Refactor send_text_message and send_image
def send_text_message(access_token, recipient_id, text, passive=False):
    """
    Note: MESSAGE_TAG is introduced to circumvent 24+1h window limit
    """
    escaped_text = text.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
    args = [
        'curl',
        '-F',
        'recipient={"id":"%s"}' % recipient_id,
        '-F',
        'message={"text": "%s"}' % escaped_text
    ]
    if passive:
        args.append('-F')
        args.append('messaging_type=MESSAGE_TAG')
        args.append('-F')
        args.append('tag=NON_PROMOTIONAL_SUBSCRIPTION')
    else:
        args.append('-F')
        args.append('messaging_type=RESPONSE')
    args.append(
        'https://graph.facebook.com/v2.8/me/messages?access_token={}'.format(
            access_token
        )
    )
    # Execute
    p = subprocess.Popen(args, stdout=subprocess.PIPE, shell=False)
    (output, err) = p.communicate()
    if err:
        logging.error(err)


def send_image(access_token, recipient_id, image_path,
               image_type, passive=False):
    """
    Note: MESSAGE_TAG is introduced to circumvent 24+1h window limit
    """
    args = [
        'curl',
        '-F',
        'recipient={"id":"%s"}' % recipient_id,
        '-F',
        'message={"attachment":{"type":"image", "payload":{}}}',
        '-F',
        'filedata=@{};type={}'.format(image_path, image_type)
    ]
    if passive:
        args.append('-F')
        args.append('messaging_type=MESSAGE_TAG')
        args.append('-F')
        args.append('tag=NON_PROMOTIONAL_SUBSCRIPTION')
    else:
        args.append('-F')
        args.append('messaging_type=RESPONSE')
    args.append(
        'https://graph.facebook.com/v2.8/me/messages?access_token={}'.format(
{'fraction_non_alphanumeric': 0.1649458574666331, 'fraction_numerical': 0.0060438176781667085, 'mean_word_length': 2.6174863387978142, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5587011', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1300, 'n_words': 229}