Advertisement
KKosty4ka

WOTD percentage thingy

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