def wikiquotesRandom(event, context): consumer_key = "pJJLmeF2NwUV5QsXa7PdMhcS1" consumer_secret = "lE9HiSlJmjLVUgPdMYAdtzWtaKnRAHjRNJ8BoN2JwHWF9y7zmH" access_token = "5909582-Kjqb8bRs1u9TSnXpSm03mJJQmbIqKx0FidWlBHlrMN" access_token_secret = "qOPQYFiVEsTzluosTVyywym8CKSsuHuCunNShKtBJWDTj" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.secure = True auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) lang = "english" authors = [ "Friedrich Nietzsche", "Sigmund Freud", "Stephen Hawking", "Jorge Luis Borges", "Barack Obama", "Steve Jobs", "Albert Einstein", "Gautama Buddha", "Isaac Newton", "Johann Wolfgang von Goethe", "Bill Gates", "Linus Torvalds", "Octavio Paz", "Plato", "Fyodor Dostoyevsky", "Hermann Hesse", "Franz Kafka", "Aristotle", "René Descartes", "Jacques Lacan", "Benito Juárez", "José Vasconcelos", "Anton LaVey", "Martin Luther King", "Desmond Tutu", "Mahatma Gandhi", "Napoleon I of France", "Emiliano Zapata", "Abraham Lincoln", "Vladimir Lenin", "Karl Marx", "René Descartes", "Anthony Burgess", "Anthony Bourdain", "Sun Tzu", "Alan Turing", "Ada Lovelace", "Dennis Ritchie", "Ken Thompson", "Simón Bolívar", "Diego Armando Maradona", "Rammstein", "Bono", "Bruce Lee", "Krishna", "Immanuel Kant", "Galileo Galilei" ] author = random.choice(authors) if (author == "Jorge Luis Borges") or (author == "Octavio Paz") or ( author == "Benito Juárez" ) or (author == "José Vasconcelos") or (author == "Emiliano Zapata") or ( author == "Simón Bolívar") or (author == "Diego Armando Maradona"): lang = "spanish" a = wikiquotes.random_quote(author, lang) while len(a) > 260: a = wikiquotes.random_quote(author, lang) message = a + "\n\n" + author api.update_status(status=message) return 1
def start(): # add_bot(slack) add_bot(twitter) while True: post = "" while not is_valid_twit(post): try: author = random_author() quote = wikiquotes.random_quote(author.name, author.language) post = format_quote(quote, author.name) print(post) except Exception as e: print(e) pass for bot in bots: try: bot.publish(post) except Exception as e: print(e) pass time.sleep(random.randint(MIN_MINUTES, MAX_MINUTES) * 60)
def QuoteGen(): global Quote counter = 1 Quote = wikiquotes.random_quote(random.choice(Authors), "english") while (len(Quote) > 200): print('Attempt ' + str(counter)) counter = counter + 1 Quote = wikiquotes.random_quote(random.choice(Authors), "english") print('Success!') substitutions = ["the LORD", "Jehovah", "God"] if "the LORD" in Quote or "Jehovah" in Quote or "God" in Quote: for i in substitutions: Quote = re.sub(i, '{0}', Quote) Quote = Quote.format(random.choice(Deities)) if "(" in Quote: Quote = re.sub(r" ?\([^)]+\)", "", Quote)
def onMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': self.onTextMessage(messageProtocolEntity) elif messageProtocolEntity.getType() == 'media': self.onMediaMessage(messageProtocolEntity) request_text = messageProtocolEntity.getBody() try: (author, raw_language) = request_text.rsplit(" ", 1) author = author.strip() raw_language = unicode(raw_language.strip()) answer = wikiquotes.random_quote(author, raw_language) except Exception as e: print e answer = "Ups! No entendí eso. Escribime Autor Idioma! Ejemplo: Borges español" pass outgoingMessageProtocolEntity = TextMessageProtocolEntity( answer, to = messageProtocolEntity.getFrom() ) self.toLower(outgoingMessageProtocolEntity) self.toLower(messageProtocolEntity.ack()) self.toLower(messageProtocolEntity.ack(True))
def test_random_quote(self): language = self.author.language fetch_quotes = wikiquotes.get_quotes(self.author.name, language) number_of_quotes = len(fetch_quotes) if number_of_quotes == 1: return if number_of_quotes > 1: for i in range(0, random_tries): random_quote = wikiquotes.random_quote(self.author.name, language) other_random_quote = wikiquotes.random_quote(self.author.name, language) if not random_quote == other_random_quote: return self.fail("Incorrect random quotes for {}".format(self.author.name))
def get_random_quote(from_person=None): if from_person is not None: person = random.choice(from_person) return wikiquotes.random_quote(person, "English") for _ in range(10): try: return _get_random_quote() except Exception: time.sleep(1) pass
def get(self, author): count = 0 while True: try: quote = wikiquotes.random_quote(author, "english") count += 1 if count == 10: return "404 Error" if len(quote) <= 300: json_string = {"quote": quote, "author": author} return json_string except custom_exceptions.TitleNotFound: return 500
def getQuote(author, language=False): """ This function retrieves a random quote from the selected wikiquote page. Arguments taken: author: the page to retrieve the quote from Returns: quote: the quote itself in a string count: the lenght of the quote in words language: the languages used to retrieve the quote (english or spanish) """ count = float('inf') languages = ["en", "es", "de", "fr", "it"] # Languages to search the author while count > 15: # Keep it short, no quotes longer than 15 words if language == False: for lang in languages: # Iterate trough the languages until it finds a result try: quote = wikiquotes.random_quote(author, lang) break except: exit("Couldn't get the quote for some reason.") else: try: quote = wikiquotes.random_quote(author, language) except: exit("Couuldn't get the quote for some reason.") count = quote.split(" ") count = len(count) # Count the words in the sentence if '"' in quote: quote = quote[1:-1] return quote, count
def ranlist(title): try: a = [wikiquotes.random_quote(title, "english")] except: a = [] try: b = wikiquote.quotes(title, max_quotes=1) except: b = [] Newlist = a + b for i in blacklist: if i in Newlist: Newlist.remove(i) return Newlist
def getQuote(author, language = False): """ This function retrieves a random quote from the selected wikiquote page. Arguments taken: author: the page to retrieve the quote from Returns: quote: the quote itself in a string count: the lenght of the quote in words language: the languages used to retrieve the quote (english or spanish) """ count = [] languages = ["en","es","de","fr","it"] # Languages to search the author while count > 15: # Keep it short, no quotes longer than 15 words if language == False: for lang in languages: # Iterate trough the languages until it finds a result try: quote = wikiquotes.random_quote(author,lang) break except: exit("Couldn't get the quote for some reason.") else: try: quote = wikiquotes.random_quote(author,language) except: exit("Couuldn't get the quote for some reason.") count = quote.split(" ") count = len(count) # Count the words in the sentence if '"' in quote: quote = quote[1:-1] return quote, count
# pixels padding right. # # Also define the max width and height for the quote. padding = 50 max_width = w - padding max_height = h - padding - author_font.getsize("ABCD ")[1] below_max_length = False # Only pick a quote that will fit in our defined area # once rendered in the font and size defined. while not below_max_length: person = random.choice(people) # Pick a random person from our list quote = wikiquotes.random_quote(person, "english") reflowed = reflow_quote(quote, max_width, quote_font) p_w, p_h = quote_font.getsize(reflowed) # Width and height of quote p_h = p_h * (reflowed.count("\n") + 1 ) # Multiply through by number of lines if p_h < max_height: below_max_length = True # The quote fits! Break out of the loop. else: continue # x- and y-coordinates for the top left of the quote quote_x = (w - max_width) / 2
def test_random_quote_encoding(self): author = Author.random_author() random_quote = wikiquotes.random_quote(author.name, author.language) self.assertTrue(language_manager.is_unicode(random_quote))
def get_quote(): quote = wikiquotes.random_quote("Aristotle", "english") return quote
#!/usr/bin/env python import wikiquotes from random import randint quote_source = randint(0,5) if quote_source==0: quote_page="Alice's Adventures in Wonderland" elif quote_source == 1: quote_page = "American McGee's Alice" elif quote_source == 2: quote_page = "Through the Looking-Glass" elif quote_source == 3: quote_page = "Into the Woods" elif quote_source == 4: quote_page = "Alice in Wonderland (2010 film)" else: quote_page='Alice: Madness Returns' print(wikiquotes.random_quote(quote_page,'english'))
from tensorflow import keras from keras_preprocessing import image import numpy as np import wikiquotes model = keras.applications.resnet.ResNet50(include_top=True, weights='imagenet') img = image.load_img('photo_id_john.png', target_size=(224, 224, 3)) img = np.expand_dims(img, axis=0) predictions = model.predict(img) predicted_classes = keras.applications.resnet.decode_predictions(predictions, top=2) string_search = "" for pred in predicted_classes[0]: string_search += pred[1] + " " print(string_search) quote = wikiquotes.random_quote(string_search, 'english') print(quote) # print(model.summary())
def assistant(command): if re.search(".*terminate|stop|bye|see you later|rest|deactivate.*", command): talk_to_me("Ok") sys.exit() elif 'the time' in command: strTime = datetime.datetime.now().strftime("%H:%M:%S") talk_to_me(f"The time is {strTime}") elif 'wikipedia' in command: # command syntax : wikipedia <topic name> command = command.replace("wikipedia", "") results = wikipedia.summary(command, sentences=2) talk_to_me("According to Wikipedia" + results) elif 'joke' in command: talk_to_me(pyjokes.get_joke()) elif "where is" in command: # command syntax : where is <location> command = command.replace("where is", "") location = command talk_to_me("User asked to Locate"+location) webbrowser.open("https://www.google.nl/maps/place/" + location + "") elif 'quote from ' in command: # command syntax : quote from <name of a famous person > command = command.replace("quote from", "") talk_to_me(wikiquotes.random_quote(command, "english")) elif 'news' in command: webbrowser.open( "https://news.google.com/topstories?hl=en-IN&gl=IN&ceid=IN:en") elif "country" in command: # command syntax : country <country name> command = command.split(" ") name = CountryInfo(command[1]) talk_to_me(name.capital()) elif("open website" in command): # command syntax : open website <website name> command = command.split(" ") webbrowser.open(url.format(command[2])) elif re.search(".*notepad.*", command): subprocess.Popen("C:Windows\\system32\\notepad.exe") elif re.search(".*calculator.*", command): subprocess.Popen("C:Windows\\system32\\calc.exe") elif re.search(".*sublimetext.*", command): subprocess.Popen("C:\\Program Files\\Sublime Text 3\\sublime_text.exe") elif re.search(".*note.*", command): talk_to_me("PLease give a suitable filename") command = get_audio() f_txt = command+".txt" talk_to_me("What should I write in it?") command = get_audio() with open(f_txt, "w") as obj: obj.write(command) talk_to_me("please check if it's correct.") x = subprocess.Popen(["C:Windows\\system32\\notepad.exe", f_txt]) command = get_audio() if re.search(".*yes|yep.*", command): x.kill() elif re.search(".*no|not|wrong.*", command): talk_to_me("Please make the necessary changes in it") elif re.search(".*active|recovered|deaths|confirmed.*", command): type_c = re.findall(".*(active|recovered|deaths|confirmed).*", command) command = command.split(" ") if command[-1] == "world": x = covid.get_total_active_cases() else: x = covid.get_status_by_country_name(command[-1]) x = x[type_c[0]] if type_c[0] == "deaths": talk_to_me( f"The number of {type_c[0]} due to covid 19 in {command[-1]} are {x} ") else: talk_to_me( f"The number of {type_c[0]} covid-19 cases in {command[-1]} are {x} ") else: driver = webdriver.Chrome() driver.get("https://www.google.com/search?q="+ command)
def get(self, author): quote = wikiquotes.random_quote(author, "english") result = quote + "\n" +author return result
async def search(ctx, author): await ctx.send(wikiquotes.random_quote(author, "english"))