KKosty4ka

WOTD percentage thingy

Feb 17th, 2023 (edited)
892
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. """
  2. WOTD percentage thingy
  3. by KKosty4ka
  4. version 1.3.0
  5.  
  6. Idea 100% stolen from Bzuki
  7. """
  8.  
  9. from colour import Color
  10. import re
  11.  
  12. # ratings go here
  13. ratings = """┆ 👍  43  / 👎  45  ┆
  14. ┆ 👍  44  / 👎  48  ┆
  15. ┆ 👍  38  / 👎  46  ┆
  16. ┆ 👍  37  / 👎  46  ┆
  17. ┆ 👍  42  / 👎  46  ┆
  18. ┆ 👍  42  / 👎  47  ┆
  19. ┆ 👍  43  / 👎  24  ┆
  20. ┆ 👍  60  / 👎  126 ┆
  21. ┆ 👍  53  / 👎  23  ┆
  22. ┆ 👍  14  / 👎  10  ┆
  23. ┆ 👍  15  / 👎  9   ┆
  24. ┆ 👍  12  / 👎  17  ┆
  25. ┆ 👍  16  / 👎  9   ┆
  26. ┆ 👍  13  / 👎  11  ┆
  27. ┆ 👍  12  / 👎  10  ┆
  28. ┆ 👍  11  / 👎  13  ┆
  29. ┆ 👍  1   / 👎  1   ┆
  30. ┆ 👍  0   / 👎  3   ┆
  31. ┆ 👍  1   / 👎  1   ┆
  32. ┆ 👍  1   / 👎  1   ┆"""
  33.  
  34.  
  35. # utils
  36. def get_suffix(num: int) -> str:
  37.     s = str(num)
  38.  
  39.     if num > 10 and num < 14: return "th"
  40.     elif s.endswith("1"): return "st"
  41.     elif s.endswith("2"): return "nd"
  42.     elif s.endswith("3"): return "rd"
  43.  
  44.     return "th"
  45.  
  46.  
  47. # get the like/dislike ratios
  48. ratios = []
  49. matches = re.finditer(r"^┆ 👍  (\d+?) +?\/ 👎  (\d+?) +?┆$", ratings, re.MULTILINE | re.UNICODE)
  50.  
  51. for match in matches:
  52.     likes = int(match.group(1))
  53.     dislikes = int(match.group(2))
  54.  
  55.     ratios.append(likes / (likes + dislikes) * 100)
  56.  
  57.  
  58. # prepare the color gradient
  59. red = Color("red")
  60. green = Color("green")
  61. colors = list(green.range_to(red, len(ratios)))
  62.  
  63.  
  64. # generate the output
  65. top = sorted(ratios, reverse=True)
  66. print("\x1bxHow close is your world is to being nominated:")
  67.  
  68. for num, i in enumerate(ratios):
  69.     top_pos = top.index(i)
  70.     hexcolor = colors[top_pos].hex_l[1::]
  71.  
  72.     print(f"\x1bF{hexcolor}{top_pos + 1}{get_suffix(top_pos + 1)} ({round(i, 2)}%)    ")
  73.  
  74. print(f"\x1bxAverage: {round(sum(ratios) / len(ratios), 2)}%")
Advertisement
Comments
Add Comment
Please, Sign In to add comment