Advertisement
Guest User

Soulsborne ranking

a guest
May 3rd, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | Gaming | 0 0
  1. import praw
  2. import re
  3. from collections import Counter, defaultdict
  4.  
  5. # Replace these with your Reddit app credentials
  6. REDDIT_CLIENT_ID = 'CLIENT_ID'
  7. REDDIT_CLIENT_SECRET = 'SECRET_ID'
  8. REDDIT_USER_AGENT = 'GameRankScraperBot/0.1 by YOUR_USERNAME'
  9.  
  10. # Initialize Reddit client
  11. reddit = praw.Reddit(
  12.     client_id=REDDIT_CLIENT_ID,
  13.     client_secret=REDDIT_CLIENT_SECRET,
  14.     user_agent=REDDIT_USER_AGENT
  15. )
  16.  
  17. # Function to extract ranked game lists from text
  18. def extract_ranked_games(text):
  19.     pattern = re.compile(r'^\s*(\d{1,2})\.\s*(.+)', re.MULTILINE)
  20.     matches = pattern.findall(text)
  21.     ranked_games = [game.strip() for _, game in matches]
  22.     return ranked_games if len(ranked_games) >= 2 else []  # ignore single-item "lists"
  23.  
  24. # Mapping of aliases to canonical names (always use the first name)
  25. NORMALIZATION_MAP = {
  26.     "BB": "Bloodborne",
  27.     "Bb": "Bloodborne",
  28.     "BloodBorne": "Bloodborne",
  29.     "BLOODBORNE": "Bloodborne",
  30.  
  31.     "Sekiro: Shadows Die Twice": "Sekiro",
  32.  
  33.     "DS3": "Dark Souls 3",
  34.     "Ds3": "Dark Souls 3",
  35.     "Dark souls 3": "Dark Souls 3",
  36.     "Dark Souls III": "Dark Souls 3",
  37.     "dark souls 3": "Dark Souls 3",
  38.  
  39.     "DS2": "Dark Souls 2",
  40.     "Ds2": "Dark Souls 2",
  41.     "Dark souls 2": "Dark Souls 2",
  42.     "Dark souls II": "Dark Souls 2",
  43.  
  44.     "Dark souls": "Dark Souls",
  45.     "Dark Souls 1": "Dark Souls",
  46.     "DS1": "Dark Souls",
  47.     "Ds1": "Dark Souls",
  48.     "Dark souls 1": "Dark Souls",
  49.     "dark souls": "Dark Souls",
  50.     "DS": "Dark Souls",
  51.  
  52.     "Demonโ€™s Souls": "Demon's Souls",
  53.     "Demon Souls": "Demon's Souls",
  54.     "DeS": "Demon's Souls",
  55.     "Demons souls": "Demon's Souls",
  56.     "Demon souls": "Demon's Souls",
  57.     "Demons Souls": "Demon's Souls",
  58.     "Demons souls remake": "Demon's Souls",
  59.  
  60.     "Elden ring": "Elden Ring",
  61.     "ER": "Elden Ring",
  62.     "Elden RIng": "Elden Ring",
  63.     "Elden ring (just a masterpiece overall)": "Elden Ring",
  64.  
  65. }
  66.  
  67. def normalize_game_name(name):
  68.     return NORMALIZATION_MAP.get(name.strip(), name.strip())
  69.  
  70. # Main function to process the Reddit thread
  71. def scrape_reddit_thread(thread_url):
  72.     submission = reddit.submission(url=thread_url)
  73.     submission.comments.replace_more(limit=None)
  74.     game_counter = Counter()
  75.     all_rankings = []
  76.  
  77.     position_scores = defaultdict(int)
  78.     appearance_counts = Counter()
  79.  
  80.     for comment in submission.comments.list():
  81.         games = extract_ranked_games(comment.body)
  82.         if games:
  83.             for i, game in enumerate(games):
  84.                 normalized = normalize_game_name(game)
  85.                 score = max(10 - i, 1)
  86.                 position_scores[normalized] += score
  87.                 appearance_counts[normalized] += 1
  88.  
  89.     print("Weighted scores (rank-sensitive):")
  90.     for game, score in sorted(position_scores.items(), key=lambda x: x[1], reverse=True)[:15]:
  91.         avg_rank = score / appearance_counts[game]
  92.         print(f"{game}: Total Score = {score}, Avg Score = {avg_rank:.2f}, Mentions = {appearance_counts[game]}")
  93.  
  94.     return {
  95.         "position_scores": position_scores,
  96.         "appearance_counts": appearance_counts,
  97.         "all_rankings": all_rankings
  98.     }
  99.  
  100. # Replace with the URL of your Reddit thread
  101. REDDIT_THREAD_URL = 'THREAD_URL'
  102.  
  103. # Run the scraper
  104. if __name__ == "__main__":
  105.     scrape_reddit_thread(REDDIT_THREAD_URL)
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement