def test_99999(self): number = 99999 word = fino.to_finnish(number) self.assertEqual( word, "yhdeksänkymmentäyhdeksäntuhattayhdeksänsataayhdeksänkymmentäyhdeksän" )
def test_999999(self): number = 999_999 word = fino.to_finnish(number) self.assertEqual( word, "yhdeksänsataayhdeksänkymmentäyhdeksäntuhatta" "yhdeksänsataayhdeksänkymmentäyhdeksän", )
def test_287654321004(self): number = 287_654_321_004 word = fino.to_finnish(number) self.assertEqual( word, "kaksisataakahdeksankymmentäseitsemänmiljardia" "kuusisataaviisikymmentäneljämiljoonaa" "kolmesataakaksikymmentäyksituhatta" "neljä", )
def test_1234567890(self): number = 1_234_567_890 word = fino.to_finnish(number) self.assertEqual( word, "miljardi" "kaksisataakolmekymmentäneljämiljoonaa" "viisisataakuusikymmentäseitsemäntuhatta" "kahdeksansataayhdeksänkymmentä", )
def build_tweet(number, reply_to=None): tweet = "" if reply_to: tweet += "@" + reply_to + " " tweet += str(number) + " " + fino.to_finnish(number) # Truncate? if len(tweet) > 280: tweet = tweet[: 280 - 1] + "…" return tweet
def check_replies(credentials): global TWITTER print("Check replies...") # TODO remove duplicate if TWITTER is None: TWITTER = twitter.Twitter( auth=twitter.OAuth( credentials["oauth_token"], credentials["oauth_token_secret"], credentials["consumer_key"], credentials["consumer_secret"], ) ) mentions = TWITTER.statuses.mentions_timeline( since_id=credentials["last_mention_id"] ) print(len(mentions), " mentions found") for i, m in enumerate(reversed(mentions)): print("*" * 80) print(i) print("text: " + m["text"]) print("in_reply_to_screen_name:", m["in_reply_to_screen_name"]) print("screen_name:", m["user"]["screen_name"]) print("ID:", m["id"]) number = extract_number_from_tweet(m["text"]) print("Found a number:", number) if number is not None: # Does the mention already include the Finnish? # If so, it's probably an edited retweet, so don't reply if fino.to_finnish(number) in m["text"]: print("Mention already includes the Finnish, don't reply") else: tweet = build_tweet(number, reply_to=m["user"]["screen_name"]) # print(tweet) tweet_it(tweet, data, in_reply_to_status_id=m["id"]) data["last_mention_id"] = m["id"] print("Save last mention ID for next time:", data["last_mention_id"]) if not args.test: save_yaml(args.yaml, data)
def test_4000biljoonaa(self): number = 4000 * 10**12 word = fino.to_finnish(number) self.assertEqual(word, "neljätuhattabiljoonaa")
def test_miljardi(self): number = 10 ** 9 word = fino.to_finnish(number) self.assertEqual(word, "miljardi")
def test_biljoona(self): number = 10**12 word = fino.to_finnish(number) self.assertEqual(word, "biljoona")
def test_10(self): number = 10 word = fino.to_finnish(number) self.assertEqual(word, "kymmenen")
def test_20(self): number = 20 word = fino.to_finnish(number) self.assertEqual(word, "kaksikymmentä")
def test_2(self): number = 2 word = fino.to_finnish(number) self.assertEqual(word, "kaksi")
def test_6(self): number = 6 word = fino.to_finnish(number) self.assertEqual(word, "kuusi")
def test_3(self): number = 3 word = fino.to_finnish(number) self.assertEqual(word, "kolme")
def test_3sentiljoonaa(self): number = 3 * 10 ** 600 word = fino.to_finnish(number) self.assertEqual(word, "kolmesentiljoonaa")
def test_range(self): # Just check no errors for number in range(0, 100_000): word = fino.to_finnish(number) self.assertNotEqual(word, "en tiedä")
def test_sentiljoona(self): number = 10 ** 600 word = fino.to_finnish(number) self.assertEqual(word, "sentiljoona")
def test_8googolia(self): number = 8 * 10 ** 100 + 1 word = fino.to_finnish(number) self.assertEqual(word, "kahdeksangoogoliayksi")
def test_googol(self): number = 10 ** 100 word = fino.to_finnish(number) self.assertEqual(word, "googol")
def test_8googolia(self): number = 8 * 10**100 + 1 word = fino.to_finnish(number) self.assertEqual(word, "kahdeksangoogoliayksi")
def test_4(self): number = 4 word = fino.to_finnish(number) self.assertEqual(word, "neljä")
def test_3sentiljoonaa(self): number = 3 * 10**600 word = fino.to_finnish(number) self.assertEqual(word, "kolmesentiljoonaa")
def test_5(self): number = 5 word = fino.to_finnish(number) self.assertEqual(word, "viisi")
def test_8(self): number = 8 word = fino.to_finnish(number) self.assertEqual(word, "kahdeksan")
def test_7(self): number = 7 word = fino.to_finnish(number) self.assertEqual(word, "seitsemän")
def test_15(self): number = 15 word = fino.to_finnish(number) self.assertEqual(word, "viisitoista")
def test_4000biljoonaa(self): number = 4000 * 10 ** 12 word = fino.to_finnish(number) self.assertEqual(word, "neljätuhattabiljoonaa")
def test_9(self): number = 9 word = fino.to_finnish(number) self.assertEqual(word, "yhdeksän")
def test_0(self): number = 0 word = fino.to_finnish(number) self.assertEqual(word, "nolla")
def test_2biljoonaa(self): number = 2 * 10**12 word = fino.to_finnish(number) self.assertEqual(word, "kaksibiljoonaa")
def test_11(self): number = 11 word = fino.to_finnish(number) self.assertEqual(word, "yksitoista")
def test_googol(self): number = 10**100 word = fino.to_finnish(number) self.assertEqual(word, "googol")
def test_sentiljoona(self): number = 10**600 word = fino.to_finnish(number) self.assertEqual(word, "sentiljoona")
def test_19(self): number = 19 word = fino.to_finnish(number) self.assertEqual(word, "yhdeksäntoista")
def test_42(self): number = 42 word = fino.to_finnish(number) self.assertEqual(word, "neljäkymmentäkaksi")
formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument("-l", "--limit", type=int, default=1_000_000, help="Upper limit") parser.add_argument("-g", "--guesses", type=int, default=3, help="Number of guesses allowed") args = parser.parse_args() number = random.randrange(args.limit + 1) print("What is " + fino.to_finnish(number) + "?") # print(number) while True: guess = input() if str(guess) == str(number): print("Yes!") break else: print("No!") args.guesses -= 1 if args.guesses > 0: print("Guess again!") else: print(number) break
def test_biljoona(self): number = 10 ** 12 word = fino.to_finnish(number) self.assertEqual(word, "biljoona")
def test_5002010(self): number = 5_002_010 word = fino.to_finnish(number) self.assertEqual(word, "viisimiljoonaakaksituhattakymmenen")
def test_miljardi(self): number = 10**9 word = fino.to_finnish(number) self.assertEqual(word, "miljardi")
def test_2biljoonaa(self): number = 2 * 10 ** 12 word = fino.to_finnish(number) self.assertEqual(word, "kaksibiljoonaa")
if __name__ == "__main__": parser = argparse.ArgumentParser( description="Guess the number.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( "-l", "--limit", type=int, default=1_000_000, help="Upper limit" ) parser.add_argument( "-g", "--guesses", type=int, default=3, help="Number of guesses allowed" ) args = parser.parse_args() number = random.randrange(args.limit + 1) print("What is " + fino.to_finnish(number) + "?") # print(number) while True: guess = input() if str(guess) == str(number): print("Yes!") break else: print("No!") args.guesses -= 1 if args.guesses > 0: print("Guess again!") else: print(number) break
def test_111111(self): number = 111_111 word = fino.to_finnish(number) self.assertEqual(word, "satayksitoistatuhattasatayksitoista")