wikipediagame: add giveup command - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit c66c8287325a231220ec51624fbb4a0f39eb414c DIR parent 4d565ad505a663f9c39318daeb7a2c5ed403ef5c HTML Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Sun, 23 Apr 2023 10:22:42 +0200 wikipediagame: add giveup command Signed-off-by: Annna Robert-Houdin <annna@bitreich.org> Diffstat: M annna-message-wikigame | 2 +- M wikipediagame | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) --- DIR diff --git a/annna-message-wikigame b/annna-message-wikigame @@ -14,7 +14,7 @@ text="$4" saytext="" case "${text}" in -init|summary|hint|more) +init|summary|hint|more|giveup) saytext="$(wikipediagame "${text}")" ;; "init "*) DIR diff --git a/wikipediagame b/wikipediagame @@ -23,6 +23,16 @@ def concealtitle(s, title): s = s.replace(titlepart, "*" * len(titlepart)) return s +def geturi(wpage): + wuri = wpage.url + return wuri.replace("https://en.wikipedia.org/wiki", "gopher://gopherpedia.com/0") + +def endgame(hintpath, titlepath): + if os.path.exists(hintpath): + os.remove(hintpath) + if os.path.exists(titlepath): + os.remove(titlepath) + def main(args): try: opts, largs = getopt.getopt(args[1:], "h") @@ -135,17 +145,16 @@ def main(args): trytext = largs[1] if title.strip().lower() == trytext.strip().lower(): wpage = w.page(title) - wuri = wpage.url - uri = wuri.replace("https://en.wikipedia.org/wiki", "gopher://gopherpedia.com/0") - print("Congrats! You have found the right title! :: %s" % (uri)) - if os.path.exists(hintpath): - os.remove(hintpath) - if os.path.exists(titlepath): - os.remove(titlepath) + print("Congrats! You have found the right title! :: %s" % (geturi(wpage))) + endgame(hintpath, titlepath) else: print("Sorry, wrong guess. (%.0f%% correct)" % \ (SequenceMatcher(None, title.strip().lower(), trytext.strip().lower()).ratio() * 100)) + if cmd == "giveup": + print("The correct title was: %s" % (geturi(wpage))) + endgame(hintpath, titlepath) + return 0 if __name__ == "__main__":