Paste Search Dynamic
Recent pastes
bansearch
  1. import praw
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import re
  5.  
  6. reddit = praw.Reddit(client_id=,
  7.                      client_secret=,
  8.                      password=,
  9.                      user_agent=,
  10.                      username=)
  11.  
  12. def bansearch(txt):
  13.     return (txt.find(" ban ") != -1) or (txt.find(" Ban ") != -1) or (txt.find("Ban ") != -1) or (txt.find(" ban.") != -1) or (txt.find("banni") != -1) or (txt.find("bannie") != -1)
  14.  
  15. Database = []
  16.  
  17.  
  18. for submission in reddit.subreddit("feminisme").hot(limit=1000):
  19.     submission.comments.replace_more(limit=none)
  20.     queue = submission.comments[:]
  21.     l,n = len(queue),0
  22.     rm = 0
  23.     tot = submission.num_comments
  24.     while queue:
  25.         comment_queue = []
  26.         comment = queue.pop(0)
  27.         if bansearch(comment.body):
  28.             n+=1
  29.         else:
  30.             comment_queue.extend(comment.replies)
  31.             while comment_queue:
  32.                 comment = comment_queue.pop(0)
  33.                 if bansearch(comment.body):
  34.                     n+=1
  35.                     comment_queue = []
  36.                 else:
  37.                     comment_queue.extend(comment.replies)
  38.     name = submission.author
  39.     ups = submission.ups
  40.     banratio = -1
  41.     if l>0:
  42.         banratio = n/l
  43.     print("Auth :",name, "Ups :", ups,"Nb coms :", tot, "Banratio :", banratio)
  44.     Database.append([name, ups, tot, banratio])
  45.  
  46. ###
  47. dicauth = {}
  48. dicups = {i:0 for i in range(0,500)}
  49. dicoms = {i:0 for i in range(0,100)}
  50. i,tot = 0,0
  51. for post in Database:
  52.     if post[0] in dicauth.keys():
  53.         dicauth[post[0]] +=1
  54.     else:
  55.         dicauth[post[0]] =1
  56.     dicups[post[1]] += 1
  57.     dicoms[post[2]] += 1
  58.     if post[2] > 2:
  59.         i+=1
  60.         tot += post[3]
  61. print(tot/i)
  62.  
  63.  
  64. key = sorted(dicauth, key=dicauth.get, reverse=true)[:10]
  65. su = 0
  66. for name in key:
  67.     su += dicauth[name]
  68.     print(name, dicauth[name])
  69. print(su)
  70. ###
  71. import csv
  72. with open('coms.csv', 'w') as f:
  73.     for key in dicoms.keys():
  74.         f.write("%s ; %sn"%(key,dicoms[key]))
  75.  
Parsed in 0.018 seconds