<commit_before>import asyncio
import discord
import sys
import traceback
import json
import requests
import pytz
from datetime import datetime, timedelta
from discord.ext import commands
from cogs.database import DatabaseCog


class Loop(DatabaseCog):
    """
    Loop events.
    """
    def __init__(self, bot):
        DatabaseCog.__init__(self, bot)
        bot.loop.create_task(self.start_update_loop())

    def __unload(self):
        self.is_active = False

    is_active = True

    last_hour = datetime.now().hour

    warning_time_period_ban = timedelta(minutes=30)
    warning_time_period_mute = timedelta(minutes=10)
    warning_time_period_nohelp = timedelta(minutes=10)

    tz = pytz.timezone('US/Pacific')

    netinfo_embed = discord.Embed(description="The Network Maintenance Information page has not been successfully checked yet.")
    # netinfo_future_embed = discord.Embed(description="This needs to be set up")

    def netinfo_parse_time(self, timestr):
        return datetime.strptime(' '.join(timestr.split()), '%A, %B %d, %Y %I :%M %p').replace(tzinfo=self.tz)

    async def update_netinfo(self):
        r = requests.get('https://www.nintendo.co.jp/netinfo/en_US/status.json?callback=getJSON')
        j = json.loads(r.text)
        now = datetime.now(self.tz)
        embed = discord.Embed(title="Network Maintenance Information / Online Status",
                              url="https://www.nintendo.co.jp/netinfo/en_US/index.html",
                              description="All times are US/Pacific.")
        embed.set_footer(text=f"This information was last updated {now.strftime('%A, %B %d, %Y %I:%M %p')}.")
        for m in j["operational_statuses"]:
            begin = self.netinfo_parse_time(m["begin"])
            if "end" in m:
                end = self.netinfo_parse_time(m["end"])
            else:
                end = datetime(year=2099, month=1, day=1, tzinfo=self.tz)
            if begin <= now < end:
                m_desc = ', '.join(m["platform"])<commit_msg>netinfo: Use aiohttp instead of requests<commit_after>import asyncio
import aiohttp
import discord
import sys
import traceback
import pytz
from datetime import datetime, timedelta
from discord.ext import commands
from cogs.database import DatabaseCog


class Loop(DatabaseCog):
    """
    Loop events.
    """
    def __init__(self, bot):
        DatabaseCog.__init__(self, bot)
        bot.loop.create_task(self.start_update_loop())

    def __unload(self):
        self.is_active = False

    is_active = True

    last_hour = datetime.now().hour

    warning_time_period_ban = timedelta(minutes=30)
    warning_time_period_mute = timedelta(minutes=10)
    warning_time_period_nohelp = timedelta(minutes=10)

    tz = pytz.timezone('US/Pacific')

    netinfo_embed = discord.Embed(description="The Network Maintenance Information page has not been successfully checked yet.")
    # netinfo_future_embed = discord.Embed(description="This needs to be set up")

    def netinfo_parse_time(self, timestr):
        return datetime.strptime(' '.join(timestr.split()), '%A, %B %d, %Y %I :%M %p').replace(tzinfo=self.tz)

    async def update_netinfo(self):
        async with aiohttp.ClientSession() as session:
            r = await session.get('https://www.nintendo.co.jp/netinfo/en_US/status.json?callback=getJSON')
            if r.status == 200:
                j = await r.json()
            else:
                # No logging setup :/
                print(f"Netinfo: {r.status} while trying to update netinfo.")
                return
        now = datetime.now(self.tz)
        embed = discord.Embed(title="Network Maintenance Information / Online Status",
                              url="https://www.nintendo.co.jp/netinfo/en_US/index.html",
                              description="All times are US/Pacific.")
        embed.set_footer(text=f"This information was last updated {now.strftime('%A, %B %d, %Y %I:%M %p')}.")
        for m in j["operational_statuses"]:
            begin = self.netinfo_parse_time(m["begin"])
            if "end" in m:
                end = self.netinfo_parse_time(m["end"])
            else:
                end = datetime(year=2099, month=1, day=1, tzinfo=self.tz)
            if begin <= now < end:
                m_desc = ', '.join(m["platform"])
{'fraction_non_alphanumeric': 0.11807005335189051, 'fraction_numerical': 0.006263048016701462, 'mean_word_length': 2.6823228010247653, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '3652708', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1282, 'n_words': 304}