<commit_before>import asyncio
import traceback
import sys
import os
import re
import math
import json
import configparser
import time
import subprocess
import functools
import sqlite3
import pathlib

from .dataclasses import Command, Message, User, Song

# Test if they have aiohttp installed in case they didn't use setup.py
try:
    import aiohttp
    aio_installed = True
except ImportError:
    print("To use stats from the API, make sure to install aiohttp. (pip install aiohttp)")
    aio_installed = False

def _setup_points_db(file):
    open(file,'a').close()
    connection = sqlite3.connect(file)
    cursor = connection.cursor()
    cursor.execute("CREATE TABLE currency (username VARCHAR(30), balance INT)")
    connection.commit()
    connection.close()

def _setup_ranks_db(file):
    open(file,'a').close()
    connection = sqlite3.connect(file)
    cursor = connection.cursor()
    cursor.execute("CREATE TABLE user_ranks (username VARCHAR(30), rankname TEXT)")
    cursor.execute("CREATE TABLE currency_ranks (currency INT, rankname TEXT)")
    cursor.execute("CREATE TABLE watched_ranks (time INT, rankname TEXT)")
    connection.commit()
    connection.close()

def _setup_time_db(file):
    open(file,'a').close()
    connection = sqlite3.connect(file)
    cursor = connection.cursor()
    cursor.execute("CREATE TABLE time_watched (username VARCHAR(30), time INT)")
    connection.commit()
    connection.close()
    
@asyncio.coroutine
def _get_url(loop, url):
    session = aiohttp.ClientSession(loop=loop)
    with aiohttp.Timeout(10):
        response = yield from session.get(url)
        try:
            # other statements
            return (yield from response.json())
        finally:
            if sys.exc_info()[0] is not None:
                # on exceptions, close the connection altogether
                response.close()
            else:
                yield from response.release()
            session.close()

def _decrease_msgcount(self):
    self.message_count -= 1

def create_timer(message, time):
    @asyncio.coroutine
    def wrapper(self):
        while True:<commit_msg>Add wrapper for database setups for efficiency™<commit_after>import asyncio
import traceback
import sys
import os
import re
import math
import json
import configparser
import time
import subprocess
import functools
import sqlite3
import pathlib

from .dataclasses import Command, Message, User, Song

# Test if they have aiohttp installed in case they didn't use setup.py
try:
    import aiohttp
    aio_installed = True
except ImportError:
    print("To use stats from the API, make sure to install aiohttp. (pip install aiohttp)")
    aio_installed = False

def db_setup(func): # easy wrapper for setring up databases
    def inner(file):
        open(file, 'a').close()
        con = sqlite3.connect(file)
        c = con.cursor()
        func(c)
        con.commit()
        con.close()
    return inner

@db_setup
def _setup_points_db(cursor):
    cursor.execute("CREATE TABLE currency (username VARCHAR(30), balance INT)")

@db_setup
def _setup_ranks_db(cursor):
    cursor.execute("CREATE TABLE user_ranks (username VARCHAR(30), rankname TEXT)")
    cursor.execute("CREATE TABLE currency_ranks (currency INT, rankname TEXT)")
    cursor.execute("CREATE TABLE watched_ranks (time INT, rankname TEXT)")

@db_setup
def _setup_time_db(cursor):
    cursor.execute("CREATE TABLE time_watched (username VARCHAR(30), time INT)")
    
@asyncio.coroutine
def _get_url(loop, url):
    session = aiohttp.ClientSession(loop=loop)
    with aiohttp.Timeout(10):
        response = yield from session.get(url)
        try:
            # other statements
            return (yield from response.json())
        finally:
            if sys.exc_info()[0] is not None:
                # on exceptions, close the connection altogether
                response.close()
            else:
                yield from response.release()
            session.close()

def _decrease_msgcount(self):
    self.message_count -= 1

def create_timer(message, time):
    @asyncio.coroutine
    def wrapper(self):
        while True:
{'fraction_non_alphanumeric': 0.09134964865519749, 'fraction_numerical': 0.006299975769323964, 'mean_word_length': 3.1951219512195124, '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': '4183403', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1170, 'n_words': 366}