Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

BBCode is not a meme

Name: Anonymous 2008-12-05 10:54

#!/usr/bin/env python
#
# bbcoder.py -- Generate enterprise grade forum posts.
#
# Copyright (C) 2008  Anonymous
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to
# the Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA  02110-1301, USA
#

import sys
import random

_codes = ('spoiler','sub','sup','b','u','o','i')

def random_bb(r):
     return _codes[r.randint(0,len(_codes)-1)]

def _main(argv=None):
    try:
        if not argv:
            argv = sys.argv
        stack = list()
        r = random.Random()
        for j in argv[1:]:
            for i in j.split():
                t = random_bb(r)
                stack.append(t)
                sys.stdout.write('[%s]%s ' % (t,i))
        for i in reversed(stack):
            sys.stdout.write('[/%s]' % i)
        sys.stdout.write('\n')
        return 0
    except IndexError:
        sys.stderr.write('you may provide me something to work on, fag.\n')

if __name__ == '__main__':
    sys.exit(_main())

Name: Anonymous 2008-12-05 16:36

Better implementation (patch)


--- bbcode.py    2008-12-05 22:31:11.000000000 +0100
+++ bbcode.py_new    2008-12-05 22:31:04.000000000 +0100
@@ -22,30 +22,26 @@
 #
 
 import sys
-import random
+from random import choice
 
 _codes = ('spoiler','sub','sup','b','u','o','i')
 
-def random_bb(r):
-     return _codes[r.randint(0,len(_codes)-1)]
-
 def _main(argv=None):
     try:
         if not argv:
             argv = sys.argv
         stack = list()
-        r = random.Random()
         for j in argv[1:]:
             for i in j.split():
-                t = random_bb(r)
+                t = choice(_codes)
                 stack.append(t)
                 sys.stdout.write('[%s]%s ' % (t,i))
-        for i in reversed(stack):
-            sys.stdout.write('[/%s]' % i)
-        sys.stdout.write('\n')
+        end = ''.join(['[/%s]' % i for i in reversed(stack)])
+        sys.stdout.write(end + '\n')
         return 0
     except IndexError:
         sys.stderr.write('you may provide me something to work on, fag.\n')
+        return 1
 
 if __name__ == '__main__':
     sys.exit(_main())

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List