def wiki(inp): '''.w/.wiki <phrase> -- gets first sentence of wikipedia ''' \ '''article on <phrase>''' x = http.get_xml(search_url, search=inp) ns = '{http://opensearch.org/searchsuggest2}' items = x.findall(ns + 'Section/' + ns + 'Item') if items == []: if x.find('error') is not None: return 'error: %(code)s: %(info)s' % x.find('error').attrib else: return 'no results found' def extract(item): return [item.find(ns + x).text for x in ('Text', 'Description', 'Url')] title, desc, url = extract(items[0]) if 'may refer to' in desc: title, desc, url = extract(items[1]) title = paren_re.sub('', title) if title.lower() not in desc.lower(): desc = title + desc desc = re.sub('\s+', ' ', desc).strip() # remove excess spaces if len(desc) > 300: desc = desc[:300] + '...' return '%s -- %s' % (desc, http.quote(http.unquote(url), ':/'))
def get_yandere_tags(inp): url = "https://yande.re/post?tags=%s" % inp.replace(" ", "_") soup = http.get_soup(url) imagelist = soup.find("ul", {"id": "post-list-posts"}).findAll("li") image = imagelist[random.randint(0, len(imagelist) - 1)] imageid = image["id"].replace("p", "") title = image.find("img")["title"] src = image.find("a", {"class": "directlink"})["href"] return "\x034NSFW\x03: \x02({})\x02 {}: {}".format(imageid, title, web.isgd(http.unquote(src)))
def get_yandere_tags(inp): url = 'https://yande.re/post?tags=%s' % inp.replace(' ','_') soup = http.get_soup(url) imagelist = soup.find('ul', {'id': 'post-list-posts'}).findAll('li') image = imagelist[random.randint(0,len(imagelist)-1)] imageid = image["id"].replace('p','') title = image.find('img')['title'] src = image.find('a', {'class': 'directlink'})["href"] return u"\x034NSFW\x03: \x02({})\x02 {}: {}".format(imageid, title, web.isgd(http.unquote(src)))
def get_yandere_tags(inp): url = 'https://yande.re/post?tags=%s' % inp.replace(' ', '_') soup = http.get_soup(url) imagelist = soup.find('ul', {'id': 'post-list-posts'}).findAll('li') image = imagelist[random.randint(0, len(imagelist) - 1)] imageid = image["id"].replace('p', '') title = image.find('img')['title'] src = image.find('a', {'class': 'directlink'})["href"] return u"\x034NSFW\x03: \x02({})\x02 {}: {}".format( imageid, title, web.isgd(http.unquote(src)))
def get_image_result(html, num): link = html.xpath("//table[@class='images_table']//a/@href")[num] image = http.unquote( re.search('.+?imgurl=(.+)&imgrefurl.+', link).group(1)) return image
def get_image_result(html,num): link = html.xpath("//table[@class='images_table']//a/@href")[num] image = http.unquote(re.search('.+?imgurl=(.+)&imgrefurl.+', link).group(1)) return image