diff --git a/utils.py b/utils.py deleted file mode 100644 index 991ac4c..0000000 --- a/utils.py +++ /dev/null @@ -1,101 +0,0 @@ -import re -from lxml import objectify, html -import httplib2 - -def auto(user,channel,word,channel_log): - file = open(channel_log) - lines = file.readlines() - - # Clean up input - lines = _reverse_list(lines) - # Take the file and reverse the list. This will help us - # match the first instance of string - lines = lines[1:] # get rid of the .autoc line - auto_line="" - for line in lines: - # first check if this line was said by the user - line_un = _get_user(line) - print line_un - print user - if user == line_un: - print line - auto_line = re.sub('.*<.*> ','',line) - break - - return spell(user,channel,auto_line,channel_log) - -def spell(user,channel,word,channel_log): - h = httplib2.Http() - troll = re.match('^[ ]*$',word) - if troll: - return "The empty set contains the empty set" - # strip extra spaces - word = re.sub('^[ ]*','',word) - - # split+the+word+for+search+format - words = word.split(' ') - query = "" - for bit in words: - query=query+"+"+bit - search = "http://www.google.com/base/feeds/snippets?q=%s" % query[1:] # There's and extra + - print search - resp, content = h.request( search ,"GET") - lxml_html = html.fromstring(content) - spell_link_objects = dict(lxml_html.xpath('//link')[1].items()) - m = re.search(r"spell=1",spell_link_objectsi['href']) - if m: - return spell_link_objects['title'] - else: - return user+", sounds right to me" - # kind of hackish. We need to wait for the popen to finish - -def s(user,channel,string,channel_log): - print string - file = open(channel_log) - lines = file.readlines() - - expr = string.split('/')[1:] # Just get the // 2 and re.search('^\d*\d$',expr[2]): - i = int(expr[2]) - while i > 0: - username =_get_user(lines[0]) - if username == user: - lines = lines[1:] - i= i-1 - else: - # We want to drop any cruft. - lines = lines[1:] - else: - lines = lines[1:] - - # Take the file and reverse the list. This will help us - # match the first instance of string - for line in lines: - # first check if this line was said by the user - line_un = _get_user(line) - # get rid of the stupid time stamp. We don't want to match that. - if line_un != user: - continue - line = re.sub('.*<.*> ','',line) - if re.search(expr[0],line): - break - - print re.sub(expr[0],expr[1],line).strip() - return user+" meant to say: "+re.sub(expr[0],expr[1],line).strip() - -def _reverse_list(lst): - r_lst=[] - for line in lst: - r_lst = [line] + r_lst - return r_lst - -def _get_user(line): - #remeber the user - m = re.match('.*<(.*)> ',line) - if not m: - return False - user = m.groups() - return user[0].strip()