def create_poem(inputwoord): w = Wikia(domain=inputwoord) wordlist = [] wordlist1 = [] print "start" while len(wordlist) < 10: for j in range(45): for i, title in enumerate(w.index(start='a', throttle=1.0, cached=True)): if i >= 3: break article = w.search(title) words = repr(article.title).split() for word in words: wordlist1.append(word.strip("u'")) for word in wordlist1: if not word[0].isupper() and word.isalpha(): wordlist.append(word) for word in wordlist: print word return wordlist
# Like Wikipedia, we can search for articles by title with Wikia.search(): print w.search("Three Headed Monkey") # However, we may not know exactly what kind of articles exist, # three-headed monkey" for example does not redirect to the above article. # We can iterate through all articles with the Wikia.articles() method # (note that Wikipedia also has a Wikipedia.articles() method). # The "count" parameter sets the number of article titles to retrieve per query. # Retrieving the full article for each article takes another query. This can be slow. i = 0 for article in w.articles(count=2, cached=True): print print article.title #print article.plaintext() i += 1 if i >= 3: break # Alternatively, we can retrieve just the titles, # and only retrieve the full articles for the titles we need: i = 0 for title in w.index(count=2): print print title #article = w.search(title) #print article.plaintext() i += 1 if i >= 3: break
# Like Wikipedia, we can search for articles by title with Wikia.search(): print(w.search("Three Headed Monkey")) # However, we may not know exactly what kind of articles exist, # three-headed monkey" for example does not redirect to the above article. # We can iterate through all articles with the Wikia.articles() method # (note that Wikipedia also has a Wikipedia.articles() method). # The "count" parameter sets the number of article titles to retrieve per query. # Retrieving the full article for each article takes another query. This can be slow. i = 0 for article in w.articles(count=2, cached=True): print("") print(article.title) #print(article.plaintext()) i += 1 if i >= 3: break # Alternatively, we can retrieve just the titles, # and only retrieve the full articles for the titles we need: i = 0 for title in w.index(count=2): print("") print(title) #article = w.search(title) #print(article.plaintext()) i += 1 if i >= 3: break
##MODULE = 'C:\Documents and Settings\dfg\Desktop\dev\wikia\pattern-2.6\pattern' ##import sys ##if MODULE not in sys.path: sys.path.append(MODULE) from pattern.web import Wikia w = Wikia(domain='lostpedia') a = w.article(query="Richard_Alpert") for i, title in enumerate(w.index(start='a', throttle=1.0, cached=True)): if i >= 8: break article = w.search(title) print repr(article.title)