Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- WOTD percentage thingy
- by KKosty4ka
- version 1.2.0
- Idea 100% stolen from Bzuki
- "egscores" are by e_g.
- """
- from colour import Color
- import re
- # ratings go here
- ratings = """┆ 👍 43 / 👎 45 ┆
- ┆ 👍 44 / 👎 48 ┆
- ┆ 👍 38 / 👎 46 ┆
- ┆ 👍 37 / 👎 46 ┆
- ┆ 👍 42 / 👎 46 ┆
- ┆ 👍 42 / 👎 47 ┆
- ┆ 👍 43 / 👎 24 ┆
- ┆ 👍 60 / 👎 126 ┆
- ┆ 👍 53 / 👎 23 ┆
- ┆ 👍 14 / 👎 10 ┆
- ┆ 👍 15 / 👎 9 ┆
- ┆ 👍 12 / 👎 17 ┆
- ┆ 👍 16 / 👎 9 ┆
- ┆ 👍 13 / 👎 11 ┆
- ┆ 👍 12 / 👎 10 ┆
- ┆ 👍 11 / 👎 13 ┆
- ┆ 👍 1 / 👎 1 ┆
- ┆ 👍 0 / 👎 3 ┆
- ┆ 👍 1 / 👎 1 ┆
- ┆ 👍 1 / 👎 1 ┆"""
- # utils
- def get_suffix(num: int) -> str:
- s = str(num)
- if num > 10 and num < 14: return "th"
- elif s.endswith("1"): return "st"
- elif s.endswith("2"): return "nd"
- elif s.endswith("3"): return "rd"
- return "th"
- # get the like/dislike ratios
- ratios = []
- egscores = []
- matches = re.finditer(r"^┆ 👍 (\d+?) +?\/ 👎 (\d+?) +?┆$", ratings, re.MULTILINE | re.UNICODE)
- for match in matches:
- likes = int(match.group(1))
- dislikes = int(match.group(2))
- ratios.append(likes / (likes + dislikes) * 100)
- egscores.append(likes / (likes + dislikes) * 100 * likes)
- # prepare the color gradient
- red = Color("red")
- green = Color("green")
- colors = list(green.range_to(red, len(ratios)))
- # generate the output
- top = sorted(ratios, reverse=True)
- print("\x1bxHow close is your world is to being nominated:")
- for num, i in enumerate(ratios):
- top_pos = top.index(i)
- hexcolor = colors[top_pos].hex_l[1::]
- print(f"\x1bF{hexcolor}{top_pos + 1}{get_suffix(top_pos + 1)} ({round(i, 2)}%) {round(egscores[num])} ")
- print(f"\x1bxAverage: {round(sum(ratios) / len(ratios), 2)}%")
Advertisement
Advertisement