# Path: onix/utilities.py
# def sanitize_string(input_string):
#     """
#     Strips all non-alphanumeric characters and puts everything in lowercase
# 
#     Args:
#         input_string (str) : string to be sanitized
# 
#     Returns:
#         str : the sanitized string
# 
#     Examples:
#         >>> from onix.utilities import sanitize_string
#         >>> print(sanitize_string('Hello World'))
#         helloworld
# 
#     """
#     return re.compile(r'[^A-Za-z0-9]').sub('', input_string).lower()


import copy
import datetime
import json
import os
import pkg_resources
from future.moves.urllib.request import urlopen
from github import Github
from py_mini_racer.py_mini_racer import MiniRacer
from onix.utilities import sanitize_string

    Returns:
        dict : the data encoded in `formats.js`, post-processed for increased
        utility

    Examples:
        >>> from onix import scrapers
        >>> commit = '5c14138b54dddf8bc034433eaef950a1c6eaf734'
        >>> formats = scrapers.scrape_formats(commit=commit)
        >>> print(formats['lc']['maxLevel'])
        5
    """

    url = 'config/formats.js'
    entry = 'Formats'
    folder = '.psdata/'
    if commit:
        folder += '{}/'.format(commit)
    filename = folder + 'formats.json'
    raw_data = json.loads(_scrape(url, entry, commit))

    formats = dict()
    for metagame in raw_data:

        if 'name' not in metagame.keys():
            continue

        # expand out rulesets
        if 'ruleset' in metagame.keys():  # I think this is always True
            for rule in copy.deepcopy(metagame['ruleset']):

# Path: onix/utilities.py
# def sanitize_string(input_string):
#     """
#     Strips all non-alphanumeric characters and puts everything in lowercase
# 
#     Args:
#         input_string (str) : string to be sanitized
# 
#     Returns:
#         str : the sanitized string
# 
#     Examples:
#         >>> from onix.utilities import sanitize_string
#         >>> print(sanitize_string('Hello World'))
#         helloworld
# 
#     """
#     return re.compile(r'[^A-Za-z0-9]').sub('', input_string).lower()


# Path: onix/scrapers.py
import copy
import datetime
import json
import os
import pkg_resources
from future.moves.urllib.request import urlopen
from github import Github
from py_mini_racer.py_mini_racer import MiniRacer
from onix.utilities import sanitize_string


    Returns:
        dict : the data encoded in `formats.js`, post-processed for increased
        utility

    Examples:
        >>> from onix import scrapers
        >>> commit = '5c14138b54dddf8bc034433eaef950a1c6eaf734'
        >>> formats = scrapers.scrape_formats(commit=commit)
        >>> print(formats['lc']['maxLevel'])
        5
    """

    url = 'config/formats.js'
    entry = 'Formats'
    folder = '.psdata/'
    if commit:
        folder += '{}/'.format(commit)
    filename = folder + 'formats.json'
    raw_data = json.loads(_scrape(url, entry, commit))

    formats = dict()
    for metagame in raw_data:

        if 'name' not in metagame.keys():
            continue

        # expand out rulesets
        if 'ruleset' in metagame.keys():  # I think this is always True
            for rule in copy.deepcopy(metagame['ruleset']):

                rule_sanitized = sanitize_string(rule)