Ejemplo n.º 1
0
	def run_revo(self, args):
		if not args:
			return "Necesas specifi vorton. Por helpo vidu %s" % self.help_url("revo")
		if args.lower() == "sal":
			return "%s/revo/sal.html" % config.zz9pza
		word = urllib.quote(util.x_to_unicode(args))
		html = util.get_html(config.revo_search % word)
		if "Neniu trafo" in html:
			return 'Nenio trovita por "%s".' % args 
		ret = []
		esperante = False
		for line in html.splitlines():
			if line.startswith("<h1>"):
				lang = re.search(r"<h1>(.+?)</h1>", line).group(1).split()[0]
				esperante = lang=="esperante"
				ret.append("-%s-" % lang)
			if line.startswith("<a"):
				if esperante:
					m = re.search(r'href="(.+?)">(.+?)</a>', line)
					eo_word, link = m.group(2).split()[0], config.revo_site+m.group(1)
					ret.append("%s %s" % (eo_word, link))
				else:
					m = re.search(r'>(.+?)</a>', line)
					word = m.group(1)
					m = re.search(r'\(.+?href="(.+?)">(.+?)</a>', line)
					eo_word, link = m.group(2).split()[0], config.revo_site+m.group(1)
					ret.append("%s (%s) %s" % (word, eo_word, link))
		return "\n".join(ret)
Ejemplo n.º 2
0
	def run_seed(self, args):
		if not args:
			return "Necesas specifi vorton. Por helpo vidu %s" % self.help_url("seed")
		word = urllib.quote(util.x_to_unicode(args))
		url = config.seed_search % word
		html = util.get_html(url)
		if "Word not found" in html:
			return 'Nenio trovita por "%s".' % args
		return url
Ejemplo n.º 3
0
	def run_kategorio(self, args):
		if not args:
			return "Necesas specifi radikon. Por helpo vidu %s" % self.help_url("kategorio")
		root = util.x_to_unicode(args)
		with open(config.kategorioj_file) as f:
			for line in f:
				if line.startswith("%s/" % root):
					return line.strip()
		return 'Nenio trovita por "%s".' % args
Ejemplo n.º 4
0
	def run_wiki(self, args):
		m = re.search(r"(-\w+)?\s*(.*)", args)
		lang = "en"
		if m.group(1):
			lang = m.group(1)[1:]
		term = m.group(2)
		term = urllib.quote(util.x_to_unicode(term))
		if not term:
			return "Necesas specifi serĉesprimon. Por helpo vidu %s" % self.help_url("wiki")
		return config.wiki_link % (lang, term)
Ejemplo n.º 5
0
	def run_majstro(self, args):
		args = args.split(None, 2)
		if len(args) < 3:
			return "Necesas specifi de-lingvon kaj al-lingvon, kaj tradukotaĵon. Por helpo vidu %s" % self.help_url("majstro")
		fr = args[0].lower()
		fr = util.iso6391_to_iso6392.get(fr, fr)
		to = args[1].lower()
		to = util.iso6391_to_iso6392.get(to, to)
		word = util.x_to_unicode(args[2])
		return self.trans_majstro(fr, to, word)
Ejemplo n.º 6
0
	def run_komputeko(self, args):
		if not args:
			return "Necesas specifi vorton. Por helpo vidu %s" % self.help_url("komputeko")
		word = urllib.quote(util.x_to_unicode(args))
		url = config.komputeko_search % word
		html = util.get_html(url)
		if "ne ekzistas en Komputeko" in html or "Bonvolu tajpi almenaŭ" in html:
			return 'Nenio trovita por "%s".' % args
		else:
			return url
Ejemplo n.º 7
0
	def run_trancxu(self, args):
		if not args:
			return "Necesas specifi vorton. Por helpo vidu %s" % self.help_url("tranĉu")
		word = urllib.quote(util.x_to_unicode(args))
		url = config.sivo_search % ("ser%c4%89o", word)
		html = util.get_html(url)
		html = re.search(r"<h2>Vortfarada Serĉo</h2>(.+?)<h2>", html, re.S).group(1)
		if "Neniu trovita" in html:
			return 'Nenio trovita por "%s".' % args
		else:
			ret = [util.strip_tags(line) for line in html.splitlines() if "<li>" in line]
			return "\n".join(ret) 
Ejemplo n.º 8
0
def main():
	d = config.log_path
	word_counter = Counter()
	nick_counter = Counter()
	kioestas_lines = []
	for log in [os.path.join(d, fn) for fn in os.listdir(d)]:
		with open(log) as f:
			for line in f:
				#[2012-09-06_14:08:13] <tommjames> this is an example message
				line = line.split(None, 2)
				if len(line) == 3:
					nick = line[1][1:-1]
					msg = line[2]
					if nick != "EoBot" and nick != "eobot":
						m = kioestas.findall(msg)
						for k in m:
							kioestas_lines.append("%s|%s" % (nick, util.x_to_unicode(k[1])))				
						if nick != "KioEstas" and nick != "kioestas" and msg and not msg[0] in "*.!":							
							msg = lower(crap.sub("", msg))
							for word in msg.split():
								if not is_exception(word):
									word = util.x_to_unicode(word)
									if word in np_particles:
										word_counter[word] += 1
										nick_counter[nick] += 1
									else:
										nocase = jn.sub("", word)
										word = nocase if nocase in np_words else parse(nocase).replace("'", "")	
										if len(word) > 1:
											word_counter[word] += 1
											nick_counter[nick] += 1
	with open(config.kioestas_file, 'w') as f:
		f.write("\n".join(kioestas_lines)) 
	with open(config.word_index_file, 'w') as f:
		for key, val in word_counter.most_common():
			f.write("%s %s\n" % (key, val))
	with open(config.nick_index_file, 'w') as f:
		for key, val in nick_counter.most_common():
			f.write("%s %s\n" % (key, val))									
Ejemplo n.º 9
0
	def run_tez(self, args):
		if not args:
			return "Necesas specifi vorton. Por helpo vidu %s" % self.help_url("tez")
		word = util.x_to_unicode(args)
		with open(config.tez_file) as f:
			ret = []
			regex = re.compile(r"(^|, )%s($|,)" % word, re.U | re.I)
			for line in f:
				m = regex.search(line)
				if m:
					ret.append(line.strip())
		if ret:
			return "\n".join(ret)
		else: 
			return 'Nenio trovita por "%s".' % args
Ejemplo n.º 10
0
	def run_av(self, args):
		if not args:
			return "Necesas specifi radikon. Por helpo vidu %s" % self.help_url("av")
		root = urllib.quote(util.x_to_unicode(args))
		html = util.get_html(config.av_search % root)
		mlnk = re.search(r'<td class="formo"><a href="(.+?)" title="Ligilo al la Fundamento">(.+?)</a></td>', html)
		mele = re.search(r'<td class="formo">(.+?)</td>', html)
		mbaz = re.search(r'<td class="bazformo">(.+?)</td>', html)
		msta = re.search(r'<td class="statuso">(.+?)</td>', html)
		mbro = re.search(r'<td class="bro">(.+?)</td>', html)
		if not mele:
			return 'Nenio trovita por "%s".' % args
		else:
			link = config.av_site + mlnk.group(1).strip() if mlnk else ""
			elemento = mlnk.group(2).strip() if mlnk else mele.group(1).strip()
			bazformo = mbaz.group(1).strip() if mbaz else ""
			statuso = re.sub(r".*? \+?", "", msta.group(1).strip()).upper()[0] if msta else ""
			bro = mbro.group(1).strip()[3] if mbro else ""
		ret = []
		ret.append("Elemento: %s %s" % (elemento, link))
		ret.append("Bazformo: %s" % bazformo)
		last = []
		if statuso:
			last.append("La radiko %s troviĝas en la" % elemento)
			if statuso == "F":
				last.append("Fundamento de Esperanto")
			else:
				last.append({"1": "Unua",
							 "2": "Dua",
							 "3": "Tria",
							 "4": "Kvara",
							 "5": "Kvina",
							 "6": "Sesa",
							 "7": "Sepa",
							 "8": "Oka",
							 "9": "Naŭa"}[statuso])
				last.append("Aldono al la Universala Vortaro")
		if bro:
			if statuso:
				last.append("kaj")
			else:
				last.append("La radiko %s troviĝas en" % elemento)
			last.append("Grupo %s de la Baza Radikaro Oficiala" % bro)
		ret.append(" ".join(last))
		return "\n".join(ret) + "."
Ejemplo n.º 11
0
	def run_traduku(self, args):		
		m = re.search(r"(-\w+)?\s*(.*)", args)
		site = ""
		if m.group(1):
			site = m.group(1)[1:]
		args = m.group(2).split(None, 2)
		if len(args) < 3:
			return "Necesas specifi de-lingvon kaj al-lingvon, kaj tradukotaĵon. Por helpo vidu %s" % self.help_url("traduku")
		fr = args[0].lower()
		to = args[1].lower()
		translate = util.x_to_unicode(args[2])
		if not site:
			site = "m" if ((fr == "eo" or to == "eo") and " " not in translate) else "gt"
		if site == "m":
			fr = util.iso6391_to_iso6392.get(fr, fr)
			to = util.iso6391_to_iso6392.get(to, to)
			return self.trans_majstro(fr, to, translate)
		else:
			return self.trans_google(fr, to, translate)
Ejemplo n.º 12
0
	def run_proverbo(self, args):
		with open(config.proverboj_file) as f:
			proverbs = f.read() if args else f.readlines()
		if args:
			word = util.x_to_unicode(args)
			proverbs = re.findall(r".*\b%s\b.*" % word, proverbs, re.U | re.I)
			if proverbs:
				if word != self.last_proverbo_word:
					self.proverbo_index = random.randint(0, len(proverbs)-1)
				elif self.proverbo_index >= len(proverbs):
					self.proverbo_index = 0
				proverb = proverbs[self.proverbo_index]
				self.proverbo_index += 1
				self.last_proverbo_word = word
				return proverb
			else:
				return 'Nenio trovita por "%s".' % args
		else:
			return random.choice(proverbs)
Ejemplo n.º 13
0
	def run_kioestas(self, args):
		if not args:
			return "Necesas specifi terminon. Por helpo vidu %s" % self.help_url("kioestas")
		with open(config.kioestas_file) as f:
			kio = f.read()
		term = util.x_to_unicode(args)
		kio = re.findall(r"(.+?)\|(\b%s\b.*)" % term, kio, re.U | re.I)
		if kio:
			if term != self.last_kioestas_term:
				self.kioestas_index = random.randint(0, len(kio)-1)
			elif self.kioestas_index >= len(kio):
				self.kioestas_index = 0
			nick = kio[self.kioestas_index][0]
			quote = kio[self.kioestas_index][1]
			self.kioestas_index += 1
			self.last_kioestas_term = term
			return "%s\n-%s" % (quote, nick)
		else:
			return 'Nenio trovita por "%s".' % args
Ejemplo n.º 14
0
	def run_rimo(self, args):
		if len(args) < 2:
			return "Necesas specifi fonemojn. Por helpo vidu %s" % self.help_url("rimo")
		phoneme = util.x_to_unicode(args)
		with open(config.kategorioj_file) as f:
			ret = []
			buf = []
			regex = re.compile(r"(.*%s)/" % phoneme, re.U | re.I)
			for line in f:
				m = regex.search(line)
				if m:
					buf.append(m.group(1))
				if len(buf) >= 30:
					ret.append(", ".join(buf))
					del buf[:]
		if buf:
			ret.append(", ".join(buf))	
		if ret:
			return "\n".join(ret)
		else: 
			return 'Nenio trovita por "%s".' % args
Ejemplo n.º 15
0
	def run_viki(self, args):
		if not args:
			return "Necesas specifi serĉesprimon. Por helpo vidu %s" % self.help_url("viki")
		term = urllib.quote(util.x_to_unicode(args))
		return config.wiki_link % ("eo", term)