<commit_before>import io
import lxml.html
import requests
import unittest

from smartbot.exceptions import *


class Plugin:
    def __init__(self):
        self.saved_items = {}

    def _search(self, terms):
        url = "http://www.xboxachievements.com/search.php"
        page = requests.post(url, data={"search": terms})
        tree = lxml.html.fromstring(page.text)

        results = []
        elements = tree.cssselect(".bl_la_main .linkT")
        for i, element in enumerate(elements[::2]):
            game_id = element.get("href")[6:-10]
            self.saved_items[i] = game_id
            results.append(element.text_content())

        return results

    def _guide(self, name):
        game_id = name.lower().replace(" ", "-")
        url = "http://www.xboxachievements.com/game/{0}/guide/".format(game_id)
        page = requests.get(url)
        tree = lxml.html.fromstring(page.text)

        li_elements = tree.cssselect("#col_l .bl_la_main_guide .showhide ul li")
        if li_elements:
            return [x.text_content().strip() for x in li_elements[:5]]
        else:<commit_msg>Update ach plugin to use requests_session<commit_after>import io
import lxml.html
import requests
import unittest

from smartbot import utils
from smartbot.exceptions import *

class Plugin:
    SEARCH_URL = "http://www.xboxachievements.com/search.php"
    GUIDE_URL = "http://www.xboxachievements.com/game/{0}/guide/"

    def __init__(self):
        self.saved_items = {}

    def _search(self, terms):
        session = utils.web.requests_session()
        page = session.post(Plugin.SEARCH_URL, data={"search": terms})
        tree = lxml.html.fromstring(page.text)

        results = []
        elements = tree.cssselect(".bl_la_main .linkT")
        for i, element in enumerate(elements[::2]):
            game_id = element.get("href")[6:-10]
            self.saved_items[i] = game_id
            results.append(element.text_content())

        return results

    def _guide(self, name):
        game_id = name.lower().replace(" ", "-")
        session = utils.web.requests_session()
        page = session.get(Plugin.GUIDE_URL.format(game_id))
        tree = lxml.html.fromstring(page.text)

        li_elements = tree.cssselect("#col_l .bl_la_main_guide .showhide ul li")
        if li_elements:
            return [x.text_content().strip() for x in li_elements[:5]]
        else:
{'fraction_non_alphanumeric': 0.13005418924551895, 'fraction_numerical': 0.005002084201750729, 'mean_word_length': 2.6253776435045317, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, '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': '3340600', 'n_tokens_mistral': 769, 'n_tokens_neox': 744, 'n_words': 150}