Commits

Anonymous committed 00dd2ca

image crop/size, count tag

  • Participants
  • Parent commits 21639f6

Comments (0)

Files changed (2)

 
     print 'parse %d comments' % count
 
-def create_image(cache, imgname):
+def create_image(cache, imgname, size=(1024,900), count=200, crop=False):
     f_comments = StringIO()
     f_topics = StringIO()
 
         for tag in tags_comments[:30]:
             print '%s:%s' % ( tag['tag'].encode('utf8'), tag['size'])
         create_tag_image(
-                tags_comments[:200], 
+                tags_comments[:count], 
                 '%s.comments.png' % imgname,
                 fontname='Ubuntu',
                 background=(0, 0, 0, 255),
-                size=(1024,900),
+                size=size,
+                crop=crop
                 )
 
     if try_topics:
         for tag in tags_topics[:30]:
             print '%s:%s' % ( tag['tag'].encode('utf8'), tag['size'])
         create_tag_image(
-                tags_topics[:200], 
+                tags_topics[:count], 
                 '%s.topics.png' % imgname,
                 fontname='Ubuntu',
                 background=(0, 0, 0, 255),
-                size=(1024,900),
+                size=size,
+                crop=crop
                 )
 
     if try_all:
             print '%s:%s' % ( tag['tag'].encode('utf8'), tag['size'])
 
         create_tag_image(
-                tags_all[:200], 
+                tags_all[:count], 
                 '%s.all.png' % imgname,
                 fontname='Ubuntu',
                 background=(0, 0, 0, 255),
-                size=(1024,900),
+                size=size,
+                crop=crop
                 )
 
 if __name__ == '__main__':
 #!/usr/bin/env python
-from optparse import OptionParser
+from optparse import OptionParser, OptionGroup
 from shelve import open as shopen
-from os.path import exists 
+from os.path import exists
+from re import compile as rcompile
 
 from lorparser import parse_comment_links,topicsfetch,create_image 
 
+re_opt_size = rcompile(r'^(\d+)x(\d+)$')
+
 parser = OptionParser(
         usage='%prog COMMAND OPTIONS',
         description = 'Commands: fetch - fetch all comment for nick, draw - draw image for nick'
         )
 
-parser.add_option(
+group = OptionGroup(parser, 'for all commands')
+
+group.add_option(
         '-n', '--nick',
-        dest='nick'
+        dest='nick',
+        help='lor nick'
         )
 
-parser.add_option(
+parser.add_option_group(group)
+
+group = OptionGroup(parser, 'for draw - fetch all comment')
+
+group.add_option(
         '-i', '--image',
-        dest='image'
+        dest='image',
+        help='image filename'
         )
+group.add_option(
+        '-c', '--count',
+        dest='tagcount',
+        type='int',
+        help='count word drawing in image(default=200)', 
+        default=200
+        )
+group.add_option(
+        '-s', '--size',
+        dest='imgsize',
+        help='size image(default=1024x900))', 
+        default=200
+        )
+group.add_option(
+        '--crop',
+        dest='crop',
+        action='store_true',
+        help='crop image after draw'
+        )
+
+parser.add_option_group(group)
 
 if __name__ == '__main__':
     (options, args) = parser.parse_args()
     if 'draw' in args:
         if not options.nick or not options.image:
             parser.error('for draw need nickname and image option')
+        m_opt_size = re_opt_size.match(options.imgsize)
+        if not m_opt_size:
+            parser.error('invalid format size options need like "100x100" ')
+        else:
+            isize = (int(m_opt_size.group(1)), int(m_opt_size.group(2)))
         draw = True
 
     cachename = '%s.cache2' % options.nick
         topicsfetch(options.nick, cache)
 
     if draw:
-        create_image(cache, options.image)
+        create_image(cache, options.image, size=isize, count=options.tagcount,
+                crop = options.crop)
 
     cache.close()