Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- import string
- import logging
- import collections
- import sys
- from sets import Set
- from collections import Counter
- from praw import BaseReddit
- from pprint import pprint
- user_agent = ("Script by /u/PostYourSinks") #User ID Name
- r = praw.Reddit(user_agent=user_agent) #establish contact with reddit
- r.login('InfoUserBot', '******************')
- punctuation = " " + string.punctuation + "\n"
- commonWords = set()
- allowed_chars = Set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- for line in open("common-words.txt", "r"):
- commonWords.add(line.strip(punctuation).lower())
- while True:
- newMessage = r.get_unread(limit=None)
- for message in newMessage:
- if "/mostusedwords" == message.body:
- tfcomment = message.was_comment
- if not tfcomment:
- message.mark_as_read()
- most_used_words = Counter()
- user = message.author
- comments = user.get_comments(limit=None)
- links = user.get_submitted(limit=None)
- for comment in comments:
- body = comment.body
- for word in body.split():
- if Set(word).issubset(allowed_chars) and word.isalnum():
- s = False
- sword = str(word).lower()
- if word.endswith("s") and word != 'was':
- singular = word[:-1]
- if most_used_words[singular] > 0:
- most_used_words[singular] += 1
- s = True
- if len(sword) < 16 and sword not in commonWords and s == False:
- most_used_words[sword] += 1
- for link in links:
- body = link.selftext
- for word in body.split():
- if Set(word).issubset(allowed_chars) and word.isalnum():
- s = False
- sword = str(word).lower()
- if word.endswith("s"):
- singular = word[:-1]
- if most_used_words[singular] > 0:
- most_used_words[singular] += 1
- s = True
- if len(sword) < 16 and sword not in commonWords and s == False:
- most_used_words[sword] += 1
- zewDict = Counter(most_used_words).most_common(10)
- newDict = dict(zewDict)
- keys = newDict.keys()
- values = newDict.values()
- msg = ('Here is your breakdown of your most used words: \n\n'
- 'Word | Times Used'
- '\n:--:|:--:')
- msg = "Here is your breakdown of your most used words:\n\nWords | Times Used\n:--:|:--:\n"
- msg += '\n'.join('%s|%s' % (k.capitalize(), v) for (k, v) in most_used_words.most_common(10))
- r.send_message(user, 'Most Used Words', msg)
- print('Message sent to user %s' % (user))
- time.sleep(4)
- else:
- time.sleep(4)
- time.sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment