<commit_before>import random

import requests
from bs4 import BeautifulSoup

from pyaib.plugins import keyword, plugin_class
from pyaib.db import db_driver

@plugin_class
@plugin_class.requires('db')
class Cookie(object):
	def __init__(self, context, config):
		self.db = context.db.get('cookies')
		self.cookies = list(self.db.getAll())
		print "%s cookies are in the jar." % len(self.cookies)
	
	
	def scancookies(self):
		""" Parse the list of cookies and add them to the db """
		print "scanning cookies..."
		counter = 0
		
		page = requests.get("http://en.wikipedia.org/wiki/List_of_cookies")
		soup = BeautifulSoup(page.text)
		
		# grab each table row, drop the header
		cookie_cells = [tr.td for tr in soup.table.find_all("tr")][1:]
		# grab the cookie name from each row, some have links and some don't
		self.cookies = [getattr(c.contents[0], "text", None) or getattr(c, "text", None) for c in cookie_cells]
		
		# Fill the database
		for c in self.cookies:
			print "adding %s to the cookie jar" % c
			item = self.db.get(c)
			item.commit()		
	
	
	@keyword("cookie")
	def keyword_cookie(self, context, msg, trigger, args, kargs):
		""" hand out some cookies """
		
		# choose a random cookie
		cookie = random.choice(self.cookies)
		
		target_user = " ".join(args)
		context.PRIVMSG(
			msg.channel or msg.sender, 
			"\x01ACTION hands %s a %s from the cookie jar.\x01" % (
				target_user or msg.sender, 
				cookie
				)
			)
	
	
	@keyword("scancookies")
	def keyword_scancookies(self, context, msg, trigger, args, kargs):
		""" load the cookie list into the database """
		<commit_msg>fix the bug that made cookies not persist by storing a value in the key<commit_after>import random

import requests
from bs4 import BeautifulSoup

from pyaib.plugins import keyword, plugin_class
from pyaib.db import db_driver

@plugin_class
@plugin_class.requires('db')
class Cookie(object):
	def __init__(self, context, config):
		self.db = context.db.get('cookies')
		self.cookies = list(self.db.getAll())
		print "%s cookies are in the jar." % len(self.cookies)
	
	
	def scancookies(self):
		""" Parse the list of cookies and add them to the db """
		print "scanning cookies..."
		counter = 0
		
		page = requests.get("http://en.wikipedia.org/wiki/List_of_cookies")
		soup = BeautifulSoup(page.text)
		
		# grab each table row, drop the header
		cookie_cells = [tr.td for tr in soup.table.find_all("tr")][1:]
		# grab the cookie name from each row, some have links and some don't
		self.cookies = [getattr(c.contents[0], "text", None) or getattr(c, "text", None) for c in cookie_cells]
		
		# Fill the database
		for c in self.cookies:
			print "adding %s to the cookie jar" % c
			item = self.db.get(c)
			item.value = c
			item.commit()		
	
	
	@keyword("cookie")
	def keyword_cookie(self, context, msg, trigger, args, kargs):
		""" hand out some cookies """
		
		# choose a random cookie
		cookie = random.choice(self.cookies)
		
		target_user = " ".join(args)
		context.PRIVMSG(
			msg.channel or msg.sender, 
			"\x01ACTION hands %s a %s from the cookie jar.\x01" % (
				target_user or msg.sender, 
				cookie
				)
			)
	
	
	@keyword("scancookies")
	def keyword_scancookies(self, context, msg, trigger, args, kargs):
		""" load the cookie list into the database """
		
{'fraction_non_alphanumeric': 0.12080536912751678, 'fraction_numerical': 0.004881025015253203, 'mean_word_length': 3.579608938547486, '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': '1154519', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1076, 'n_words': 350}