def find_quotes(): i = 0 first = "" second = "" third = "" dict = {} while i < 3: quote_index = wikiquote.random_titles() try: title = random.choice(quote_index) quotes = wikiquote.quotes(title) if not quotes: raise EmptyException except DisambiguationPageException: quotes = wikiquote.qotd() title = quotes[1] except EmptyException: quotes = wikiquote.qotd() title = quotes[1] syl = 0 line = "" for word in quotes[0].split(" "): if "." in word: syl += sylco(word) line += word line += " " break syl += sylco(word) line += word line += " " if not first and syl is 5: first = line dict[first] = title i += 1 elif not second and syl is 7: second = line dict[second] = title i += 1 elif not third and syl is 5: third = line dict[third] = title i += 1 # save_path = "C:/Users/natha/Documents/Personal Projects/quotes/Haikus" # file = os.path.join(save_path, dict[first]+".txt") # f = open(file, "w") # f.write('\n' + "Haiku:" + '\n' + first + '\n' + second + '\n' + third + '\n') # f.write('\n' + "Authors:" + '\n' + dict[first] + '\n' + dict[second] + '\n' + dict[third]) content = '\n' + "Haiku:" + '\n' + first + '\n' + second + '\n' + third + '\n' content += '\n' + "Haiku:" + '\n' + first + '\n' + second + '\n' + third + '\n' return dict[first], content
def run(self, dispatcher, tracker, domain): print() print("======Inside Action Today Quote ====") print() print(len(wikiquote.qotd())) qotd = '~'.join(wikiquote.qotd()) print(qotd) dispatcher.utter_message(text="Here is the Quote of the Day.", json_message={ "payload": "wikiquote", "text": qotd }) return []
def menu(bot, update): if latest_menu is None: send_error_msg(bot, update, "Ich kann kein Menü für heute finden.") return menu = "" try: qotd = wikiquote.qotd(lang='de') except: try: qotd = wikiquote.qotd() except: qotd = [ "Ich konnte kein Zitat für diese Woche finden", "Prof. Dr. med. Mensa Bot" ] menu += "Zitat der Woche:" + "\n" + "\"" + qotd[0] + "\", " + qotd[ 1] + "\n\n" #menu += "Prof. Dr. Mensa Bot 2.7 will not be maintained past 2020." + "\n\n" menu += "Menü für " + latest_menu["Datum"] + "\n\n" for i in latest_menu["Menu"]: tag_line = "" for tag in i.tags: tag_line += tag if tag != "Kinderteller" else "" menu += (tag_line + i.allergens() + " | " + i.beautiful_description() + ", " + i.price + "\n") menu = helpers.emojify(menu) if type(update) == int: chat_id = update else: chat_id = update.message.chat_id bot.sendMessage(chat_id=chat_id, text=menu, parse_mode=telegram.ParseMode.MARKDOWN)
def get_qotd(ctx): path = os.path.join(os.environ["HOME"], ".qotd") if not os.path.exists(path) or os.stat(path).st_mtime < ( time.time() - (24 * 3600) ): quote, title = qotd(lang=ctx.obj["lang"]) text = pretty(quote, title) print(text, file=open(path, mode="w")) else: # Read quote from file print("Found previous ~/.qotd", file=sys.stderr) # os.system(f'cat {path}') with open(path, mode="r") as fd: while line := fd.readline().strip("\n"): print(line)
def get_random_quotes(): try: return wq.qotd() except: return "Quote not found"
def test_qotd_qotd(): assert wikiquote.quote_of_the_day() == wikiquote.qotd()
def test_qotd_qotd(self): self.assertEqual(wikiquote.quote_of_the_day(), wikiquote.qotd())