Merge pull request #100 from bradleyjones/check-tweet-length
authorOrakaro <DTVD@users.noreply.github.com>
Fri, 31 Jul 2015 01:40:33 +0000 (10:40 +0900)
committerOrakaro <DTVD@users.noreply.github.com>
Fri, 31 Jul 2015 01:40:33 +0000 (10:40 +0900)
Check tweet length

1  2 
rainbowstream/rainbow.py

diff --combined rainbowstream/rainbow.py
@@@ -68,16 -68,6 +68,16 @@@ def parse_arguments()
          action='store_true',
          help='Display all image on terminal.')
      parser.add_argument(
 +        '-24',
 +        '--color-24bit',
 +        action='store_true',
 +        help='Display images using 24bit color codes.')
 +    parser.add_argument(
 +        '-hr',
 +        '--higher-resolution',
 +        action='store_true',
 +        help='Display images in high(er) resolution.')
 +    parser.add_argument(
          '-ph',
          '--proxy-host',
          help='Use HTTP/SOCKS proxy for network connections.')
@@@ -244,11 -234,6 +244,11 @@@ def init(args)
      # Image on term
      c['IMAGE_ON_TERM'] = args.image_on_term
      set_config('IMAGE_ON_TERM', str(c['IMAGE_ON_TERM']))
 +    # Use 24 bit color
 +    c['24BIT'] = args.color_24bit
 +    # Print images using half height blocks
 +    c['HIGHER_RESOLUTION'] = args.higher_resolution
 +    set_config('HIGHER_RESOLUTION', str(c['HIGHER_RESOLUTION']))
      # Check type of ONLY_LIST and IGNORE_LIST
      if not isinstance(c['ONLY_LIST'], list):
          printNicely(red('ONLY_LIST is not a valid list value.'))
@@@ -1306,7 -1291,7 +1306,7 @@@ def switch()
              return
          # Kill old thread
          g['stream_stop'] = True
 -        try: 
 +        try:
              stuff = g['stuff'].split()[1]
          except:
              stuff = None
@@@ -1956,13 -1941,15 +1956,15 @@@ def listen()
              c['lock'] = True
              # Save cmd to global variable and call process
              g['stuff'] = ' '.join(line.split()[1:])
-             # Process the command
-             process(cmd)()
-             # Not re-display
-             if cmd in ['switch', 't', 'rt', 'rep']:
-                 g['prefix'] = False
-             else:
-                 g['prefix'] = True
+             # Check tweet length
+             if check_tweet_length():
+                 # Process the command
+                 process(cmd)()
+                 # Not re-display
+                 if cmd in ['switch', 't', 'rt', 'rep']:
+                     g['prefix'] = False
+                 else:
+                     g['prefix'] = True
              # Release the semaphore lock
              c['lock'] = False
          except EOFError:
              printNicely(red('OMG something is wrong with Twitter right now.'))
  
  
+ def check_tweet_length():
+     """
+     Check tweet length (should be <= 140 chars)
+     """
+     length = len(g['stuff'])
+     if length <= 140:
+         return True
+     printNicely(red("Message is too long: %s chars" % length))
+     return False
  def reconn_notice():
      """
      Notice when Hangup or Timeout