<commit_before>import json
import posixpath
import urllib.parse
from pprint import pprint

import requests
import re

from util import Events

# Replace with the correct URL
url = "https://api.e-hentai.org/api.php"
json_request_headers = "{'content-type': 'application/json'}"


class Plugin(object):
    def __init__(self, pm):
        self.pm = pm
        self.name = "Exhentai"

    @staticmethod
    def register_events():
        return [Events.Message("Exhentai")]

    async def handle_message(self, message_object):
        exhentailinks = re.findall(r'(https://exhentai.org/g/([0-9]+)/([0-9a-f]{10})/)', message_object.content)

        for entry in exhentailinks:
            checkvalid = requests.head(entry[0])
            if checkvalid.ok:
                gallery_id = entry[1]
                gallery_token = entry[2]
                payload = (
                    '{"method": "gdata","gidlist": [[' + gallery_id + ',"' + gallery_token + '"]],"namespace": 1}')
                response = requests.post(url, payload, json_request_headers)
                if response.ok:
                    await self.pm.clientWrap.send_message(self.name, message_object.channel,
                                                          json.dumps(response.json(), sort_keys=True, indent=4))<commit_msg>prints relativly pretty formatted json from exhentai api link<commit_after># from pprint import pprint
import json
import requests
import re

from util import Events

# Replace with the correct URL
url = "https://api.e-hentai.org/api.php"
json_request_headers = "{'content-type': 'application/json'}"


class Plugin(object):
    def __init__(self, pm):
        self.pm = pm
        self.name = "Exhentai"

    @staticmethod
    def register_events():
        return [Events.Message("Exhentai")]

    async def handle_message(self, message_object):
        exhentailinks = re.findall(r'(https://exhentai.org/g/([0-9]+)/([0-9a-f]{10})/)', message_object.content)
        for entry in exhentailinks:
            checkvalid = requests.head(entry[0])
            if checkvalid.ok:
                gallery_id = entry[1]
                gallery_token = entry[2]
                payload = (
                    '{"method": "gdata","gidlist": [[' + gallery_id + ',"' + gallery_token + '"]],"namespace": 1}')
                response = requests.post(url, payload, json_request_headers)
                if response.ok:
                    await self.pm.clientWrap.send_message(self.name, message_object.channel,
                                                          json.dumps(response.json(), sort_keys=True, indent=4))
{'fraction_non_alphanumeric': 0.12619502868068833, 'fraction_numerical': 0.008413001912045888, 'mean_word_length': 2.2659176029962547, 'pattern_counts': {'":': 6, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1261808', 'n_tokens_mistral': 774, 'n_tokens_neox': 750, 'n_words': 164}