<commit_before># -*- coding: utf-8 -*-

# Plugin created by Merola

import re
import string
import urllib
import utility
from commands import Command

def decode_characters(encoded_string):
	strlen = len(encoded_string)
	decoded_string = ""
	regex = re.compile("\\\\u[0-9a-f]{4}")
	i = 0
	
	while i < (strlen - 5):
		if regex.match(encoded_string[i:i+6]):
			decoded_string += unichr(int(encoded_string[i+2:i+6], 16))
			i += 6
		else:
			decoded_string += encoded_string[i]
			i += 1
	
	if i == (strlen - 5):
		decoded_string += encoded_string[i:strlen]
	
	return decoded_string
	
def prisjakt_search(query_string):
	# Build URLs
	url_product = 'http://www.prisjakt.nu/ajax/jsonajaxserver.php?' + \
			'm=super_search&p={"mode"%3A"' + 'prod_pj' + \
			'"%2C"search"%3A"' + query_string + '"%2C"limit"%3A1%2C"v4"%3A1}'
	url_book = 'http://www.prisjakt.nu/ajax/jsonajaxserver.php?' + \
			'm=super_search&p={"mode"%3A"' + 'bok' + \
			'"%2C"search"%3A"' + query_string + '"%2C"limit"%3A1%2C"v4"%3A1}'

	# Fetch the product result page
	response = utility.read_url(url_product)
	data = response["data"]

	# Look for info
	id_pattern = "\\{'mode': 'produkt', 'produkt_id': '(\\d+)'\\}"
	id_match = re.search(id_pattern, data)

	if not id_match:
		# Fetch the book result page
		response = utility.read_url(url_book)
		data = response["data"]

		# Look for info
		id_pattern = "\\{'mode': 'bok', 'produkt_id': '(\\d+)'\\}"
		id_match = re.search(id_pattern, data)

		url_type = "bok"
	else:
		url_type = "produkt"

	if id_match:
		# We seem to have found something
		product_id = id_match.group(1)

		# Get title
		title_pattern = "class=\\\\\"ikon(14)?\\\\\"( alt=\\\\\"\\\\\")?\\> (.+?) \\\\n"
		encoded_title = re.search(title_pattern, data).group(3)
		# Remove HTML tags
		encoded_title = string.replace(
				encoded_title, '<span class=\\"search_hit\\">', '')
		encoded_title = string.replace(encoded_title, '<\\/span>', '')
		# Decode special characters
		product_title = decode_characters(encoded_title)

		# Get price
		price_pattern = "\\<span class=\\\\\"pris\\\\\"\>(\\d+:-)\\<\\\\\/span\\>"
		product_price = re.search(price_pattern, data).group(1)

		# Done, return info string
		return product_title + ", " + product_price + \
				", http://www.prisjakt.nu/" + url_type + ".php?p=" + product_id + \
				" | All results: http://www.prisjakt.nu/search.php?query=" + query_string
	else:
		return "No product found."

def prisjakt_product(url):
	# Fetch the web page
	response = utility.read_url(url)
	data = response["data"]
	data = data.replace("&nbsp;", "")

	# Look for title
	title_pattern = "\<h1.*?\>(\<a href=\".+?\"\>)?(.+?)(\<\/a\>)?\<\/h1\>"<commit_msg>Perhaps IRCclient.send() will be happier if served latin-1 strings.<commit_after># -*- coding: utf-8 -*-

# Plugin created by Merola

import re
import string
import urllib
import utility
from commands import Command

def decode_characters(encoded_string):
	strlen = len(encoded_string)
	decoded_string = ""
	regex = re.compile("\\\\u[0-9a-f]{4}")
	i = 0
	
	while i < (strlen - 5):
		if regex.match(encoded_string[i:i+6]):
			decoded_string += unichr(int(encoded_string[i+2:i+6], 16))
			i += 6
		else:
			decoded_string += encoded_string[i]
			i += 1
	
	if i == (strlen - 5):
		decoded_string += encoded_string[i:strlen]
	
	return decoded_string
	
def prisjakt_search(query_string):
	# Build URLs
	url_product = 'http://www.prisjakt.nu/ajax/jsonajaxserver.php?' + \
			'm=super_search&p={"mode"%3A"' + 'prod_pj' + \
			'"%2C"search"%3A"' + query_string + '"%2C"limit"%3A1%2C"v4"%3A1}'
	url_book = 'http://www.prisjakt.nu/ajax/jsonajaxserver.php?' + \
			'm=super_search&p={"mode"%3A"' + 'bok' + \
			'"%2C"search"%3A"' + query_string + '"%2C"limit"%3A1%2C"v4"%3A1}'

	# Fetch the product result page
	response = utility.read_url(url_product)
	data = response["data"]

	# Look for info
	id_pattern = "\\{'mode': 'produkt', 'produkt_id': '(\\d+)'\\}"
	id_match = re.search(id_pattern, data)

	if not id_match:
		# Fetch the book result page
		response = utility.read_url(url_book)
		data = response["data"]

		# Look for info
		id_pattern = "\\{'mode': 'bok', 'produkt_id': '(\\d+)'\\}"
		id_match = re.search(id_pattern, data)

		url_type = "bok"
	else:
		url_type = "produkt"

	if id_match:
		# We seem to have found something
		product_id = id_match.group(1)

		# Get title
		title_pattern = "class=\\\\\"ikon(14)?\\\\\"( alt=\\\\\"\\\\\")?\\> (.+?) \\\\n"
		encoded_title = re.search(title_pattern, data).group(3)
		# Remove HTML tags
		encoded_title = string.replace(
				encoded_title, '<span class=\\"search_hit\\">', '')
		encoded_title = string.replace(encoded_title, '<\\/span>', '')
		# Decode special characters
		product_title = decode_characters(encoded_title)

		# Get price
		price_pattern = "\\<span class=\\\\\"pris\\\\\"\>(\\d+:-)\\<\\\\\/span\\>"
		product_price = re.search(price_pattern, data).group(1)

		# Done, return info string (latin-1 to make IRCClient.send() happy)
		return product_title.encode('latin-1', 'replace') + ", " + product_price + \
				", http://www.prisjakt.nu/" + url_type + ".php?p=" + product_id + \
				" | All results: http://www.prisjakt.nu/search.php?query=" + query_string
	else:
		return "No product found."

def prisjakt_product(url):
	# Fetch the web page
	response = utility.read_url(url)
	data = response["data"]
	data = data.replace("&nbsp;", "")

	# Look for title
	title_pattern = "\<h1.*?\>(\<a href=\".+?\"\>)?(.+?)(\<\/a\>)?\<\/h1\>"
{'fraction_non_alphanumeric': 0.20351390922401172, 'fraction_numerical': 0.015556368960468522, 'mean_word_length': 3.6789383561643834, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, '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': '2314939', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2102, 'n_words': 411}