From f083d5ee58223936b4a82dccc9de3c4b51f65a1b Mon Sep 17 00:00:00 2001 From: Bryce Boe Date: Sun, 1 Jul 2012 00:42:56 -0700 Subject: [PATCH] Update to use the renamed PRAW package. Also add setup.py. --- .gitignore | 8 ++++++++ README.md | 29 ++++++++++++++++++++--------- setup.py | 25 +++++++++++++++++++++++++ subreddit_stats.py | 16 +++++++--------- 4 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 .gitignore create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb3961a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +*.egg +*.pyc +.coverage +*.egg-info/ +_build/ +build/ +dist/ diff --git a/README.md b/README.md index 2f4b241..bac13ef 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,30 @@ -Introduction ---- +# Introduction subreddit_stats.py is a tool to provide basic statistics on a subreddit. To see the what sort of output subreddit stats generates check out [/r/subreddit_stats](http://www.reddit.com/r/subreddit_stats). -subreddit_stats.py depends on -[the python reddit api wrapper](/mellort/reddit_api). +# Installation -Examples ---- +## Ubuntu/debian installation + + sudo apt-get install python-setuptools + sudo easy_install pip + sudo pip install subreddit_stats + +## Mac OS X installation (only tested with Lion) + + sudo easy_install pip + sudo pip install subreddit_stats + +# Examples of how to run subreddit_stats 0. Generate stats for subreddit __foo__ for the last 30 days with extra verbose output. Post results to subreddit __bar__ as user __user__. - ``` -./subreddit_stats.py -d30 -vv -R bar -u user foo -``` + subreddit_stats -d30 -vv -R bar -u user foo + +0. Generate stats for subreddit __blah__ for the top posts of the year. Post the +results to the same subreddit as user __resu__. + + subreddit_stats --top year -u resu blah diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a31c509 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +import os +import re +from setuptools import setup + +HERE = os.path.abspath(os.path.dirname(__file__)) +MODULE_FILE = os.path.join(HERE, 'subreddit_stats.py') +README = open(os.path.join(HERE, 'README.md')) +VERSION = re.search("__version__ = '([^']+)'", + open(MODULE_FILE).read()).group(1) + + +setup(name='subreddit_stats', + version=VERSION, + author='Bryce Boe', + author_email='bbzbryce@gmail.com', + url='https://github.com/praw-dev/subreddit_stats', + description=('A tool to calculate various submission and comment ' + 'statistics on reddit communities.'), + long_description=README, + keywords = 'reddit subreddit statistics', + classifiers=['Programming Language :: Python'], + install_requires=['praw'], + py_modules=['subreddit_stats'], + entry_points = {'console_scripts': + ['subreddit_stats = subreddit_stats:main']}) diff --git a/subreddit_stats.py b/subreddit_stats.py index 27480a8..3a785a7 100755 --- a/subreddit_stats.py +++ b/subreddit_stats.py @@ -7,17 +7,17 @@ from datetime import datetime from optparse import OptionGroup, OptionParser -from reddit import Reddit -from reddit.errors import ClientException, ExceptionList, RateLimitExceeded -from reddit.objects import Comment +from praw import Reddit +from praw.errors import ClientException, ExceptionList, RateLimitExceeded +from praw.objects import Comment DAYS_IN_SECONDS = 60 * 60 * 24 MAX_BODY_SIZE = 10000 +__version__ = '0.3.0' -class SubRedditStats(object): - VERSION = '0.2.0' +class SubRedditStats(object): post_prefix = 'Subreddit Stats:' post_header = '---\n###%s\n' post_footer = ('>Generated with [BBoe](/user/bboe)\'s [Subreddit Stats]' @@ -52,11 +52,9 @@ def sleep(sleep_time): print('\tSleeping for %d seconds' % sleep_time) time.sleep(sleep_time) - while True: try: return func(*args, **kwargs) - break except RateLimitExceeded as error: sleep(error.sleep_time) except ExceptionList as exception_list: @@ -83,7 +81,7 @@ def __init__(self, subreddit, site, verbosity): self.reddit.config.comment_sort = 'top' def __str__(self): - return 'BBoe\'s SubRedditStats %s' % self.VERSION + return 'BBoe\'s Subreddit Stats %s' % __version__ def login(self, user, pswd): if self.verbosity > 0: @@ -363,7 +361,7 @@ def timef(timestamp): def main(): msg = { - 'site': 'The site to connect to defined in your reddit_api.cfg.', + 'site': 'The site to connect to defined in your praw.cfg.', 'user': ('The user to login as. If not specified the user (if any) ' 'from the site config will be used, otherwise you will be ' 'prompted for a username.'),