<commit_before>from __future__ import absolute_import, division, unicode_literals

from urlparse import urljoin

from flexget import plugin
from flexget.utils import json
from flexget.utils.requests import RequestException, Session


# Testing site
#API_KEY = '<KEY>'
#API_URL = 'http://api.v2.trakt.tv/'
# Production Site
API_KEY = '<KEY>'
API_URL = 'https://api.trakt.tv/'


def make_list_slug(name):
    """Return the slug for use in url for given list name."""
    slug = name.lower()
    # These characters are just stripped in the url
    for char in '!@#$%^*()[]{}/=?+\\|-_':
        slug = slug.replace(char, '')
    # These characters get replaced
    slug = slug.replace('&', 'and')
    slug = slug.replace(' ', '-')
    return slug


def get_session(username=None, password=None):
    """Creates a requests session which is authenticated to trakt."""
    session = Session()
    session.headers = {
        'Content-Type': 'application/json',
        'trakt-api-version': 2,
        'trakt-api-key': API_KEY
    }
    if username:
        session.headers['trakt-user-login'] = username
    if username and password:
        auth = {'login': username, 'password': password}
        try:
            r = session.post(urljoin(API_URL, 'auth/login'), data=json.dumps(auth))<commit_msg>Stop replacing underscore in trakt slugs.<commit_after>"""
Utilities to use api v2 api.

TODO: This should probably all be moved to api_trakt.py once that is converted to api v2
"""

from __future__ import absolute_import, division, unicode_literals

from urlparse import urljoin

from flexget import plugin
from flexget.utils import json
from flexget.utils.requests import RequestException, Session


# Testing site
#API_KEY = '<KEY>'
#API_URL = 'http://api.v2.trakt.tv/'
# Production Site
API_KEY = '<KEY>'
API_URL = 'https://api.trakt.tv/'


def make_list_slug(name):
    """Return the slug for use in url for given list name."""
    slug = name.lower()
    # These characters are just stripped in the url
    for char in '!@#$%^*()[]{}/=?+\\|-':
        slug = slug.replace(char, '')
    # These characters get replaced
    slug = slug.replace('&', 'and')
    slug = slug.replace(' ', '-')
    return slug


def get_session(username=None, password=None):
    """Creates a requests session which is authenticated to trakt."""
    session = Session()
    session.headers = {
        'Content-Type': 'application/json',
        'trakt-api-version': 2,
        'trakt-api-key': API_KEY
    }
    if username:
        session.headers['trakt-user-login'] = username
    if username and password:
        auth = {'login': username, 'password': password}
        try:
            r = session.post(urljoin(API_URL, 'auth/login'), data=json.dumps(auth))
{'fraction_non_alphanumeric': 0.1380065717415115, 'fraction_numerical': 0.002190580503833516, 'mean_word_length': 3.248062015503876, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '4516181', 'n_tokens_mistral': 862, 'n_tokens_neox': 838, 'n_words': 253}