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

Commit

Permalink
Added flair stats option.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Aug 11, 2012
1 parent 3d39b9d commit 89caa91
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -28,7 +28,6 @@ flair templates from existing user flair, however, it can also be used to
quickly list banned users, contributors, and moderators.

### modutils examples
---

Note: all examples require you to be a moderator for the subreddit

Expand Down
35 changes: 35 additions & 0 deletions deploy.sh
@@ -0,0 +1,35 @@
#!/bin/bash

status=$(git status | head -n 1)
if [[ "$status" != "# On branch master" ]]; then
echo "Not on master branch. Goodbye"
exit 1
fi

status=$(git status | tail -n -1)
if [[ "$status" != "nothing to commit (working directory clean)" ]]; then
echo "There are pending changes. Goodbye"
exit 1
fi

version=$(python -c "import prawtools; print prawtools.__version__")

read -p "Do you want to deploy $version? [y/n] " input
case $input in
[Yy]* ) ;;
* ) echo "Goodbye"; exit 1;;
esac

python setup.py sdist upload -s
if [ $? -ne 0 ]; then
echo "Pushing distribution failed. Aborting."
exit 1
fi

git tag -s "prawtools-$version" -m "prawtools-$version"
if [ $? -ne 0 ]; then
echo "Tagging version failed. Aborting."
exit 1
fi

git push origin master --tags
2 changes: 1 addition & 1 deletion prawtools/__init__.py
@@ -1 +1 @@
__version__ = '0.1'
__version__ = '0.2'
38 changes: 31 additions & 7 deletions prawtools/mod.py
@@ -1,5 +1,6 @@
import re
import sys
from collections import Counter
from optparse import OptionGroup
from praw import Reddit
from .helpers import arg_parser
Expand Down Expand Up @@ -154,12 +155,30 @@ def message(self, category, subject, msg_file):
print 'Sent to: %s' % str(user)

def output_current_flair(self):
self.login()
for flair in self.current_flair():
print flair['user']
print ' Text: %s\n CSS: %s' % (flair['flair_text'],
flair['flair_css_class'])

def output_flair_stats(self):
css_counter = Counter()
text_counter = Counter()
for flair in self.current_flair():
if flair['flair_css_class']:
css_counter[flair['flair_css_class']] += 1
if flair['flair_text']:
text_counter[flair['flair_text']] += 1

print 'Flair CSS Statistics'
for flair, count in sorted(css_counter.items(),
key=lambda x: (x[1], x[0])):
print '{0:3} {1}'.format(count, flair)

print 'Flair Text Statistics'
for flair, count in sorted(text_counter.items(),
key=lambda x: (x[1], x[0]), reverse=True):
print '{0:3} {1}'.format(count, flair)

def output_list(self, category):
self.login()
print '%s users:' % category
Expand All @@ -177,6 +196,7 @@ def main():
'edit': 'When adding flair templates, mark them as editable.',
'file': 'The file containing contents for --message',
'flair': 'List flair for the subreddit.',
'flair_stats': 'Display the number of users with each flair.',
'limit': ('The minimum number of users that must have the specified '
'flair in order to add as a template. default: %default'),
'list': ('List the users in one of the following categories: '
Expand All @@ -201,17 +221,19 @@ def main():
choices=mod_choices, metavar='CATEGORY', default=[])
parser.add_option('-F', '--file', help=msg['file'])
parser.add_option('-f', '--flair', action='store_true', help=msg['flair'])
parser.add_option('', '--flair-stats', action='store_true',
help=msg['flair_stats'])
parser.add_option('-m', '--message', choices=mod_choices, help=msg['msg'])
parser.add_option('', '--subject', help=msg['subject'])

group = OptionGroup(parser, 'Sync options')
group.add_option('', '--sync', action='store_true', help=msg['sync'])
group.add_option('-s', '--static', action='append', help=msg['static'])
group.add_option('', '--editable', action='store_true', help=msg['edit'])
group.add_option('', '--ignore-css', action='store_false',
default=True, help=msg['css'])
group.add_option('', '--ignore-text', action='store_false',
default=True, help=msg['text'])
group.add_option('', '--ignore-css', action='store_true',
default=False, help=msg['css'])
group.add_option('', '--ignore-text', action='store_true',
default=False, help=msg['text'])
group.add_option('', '--limit', type='int', help=msg['limit'], default=2)
group.add_option('', '--sort', action='store', choices=('alpha', 'size'),
default='alpha', help=msg['sort'])
Expand All @@ -235,11 +257,13 @@ def main():
modutils.output_list(category)
if options.flair:
modutils.output_current_flair()
if options.flair_stats:
modutils.output_flair_stats()
if options.sync:
modutils.flair_template_sync(editable=options.editable,
limit=options.limit,
static=options.static, sort=options.sort,
use_css=options.ignore_css,
use_text=options.ignore_text)
use_css=not options.ignore_css,
use_text=not options.ignore_text)
if options.message:
modutils.message(options.message, options.subject, options.file)

0 comments on commit 89caa91

Please sign in to comment.