Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Update to use the renamed PRAW package. Also add setup.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Jul 1, 2012
1 parent 0bd2481 commit f083d5e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
*~
*.egg
*.pyc
.coverage
*.egg-info/
_build/
build/
dist/
29 changes: 20 additions & 9 deletions 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
25 changes: 25 additions & 0 deletions 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']})
16 changes: 7 additions & 9 deletions subreddit_stats.py
Expand Up @@ -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]'
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.'),
Expand Down

0 comments on commit f083d5e

Please sign in to comment.