def tweets_for(query_type, args, per_user=None):
 lookup = {u'query_type': query_type, u'value': args[0]}
 try:
  tweets = Tweet.objects.get_for(**lookup)
 except TwitterQueryException:
  return []
 if (per_user is not None):
  _tweets = defaultdict(list)
  for tweet in tweets:
   if (len(_tweets[tweet.user_name]) < per_user):
    _tweets[tweet.user_name].append(tweet)
  tweets = sum(_tweets.values(), [])
  tweets.sort(key=(lambda t: t.created_at), reverse=True)
 if ((len(args) > 1) and str(args[(-1)]).isdigit()):
  tweets = tweets[:int(args[(-1)])]
 return tweets

def tweets_for ( query_type , args , per_user = None ) : lookup = { u'query_type' : query_type , u'value' : args [ 0 ] } try : tweets = Tweet . objects . get_for ( ** lookup ) except TwitterQueryException : return [ ] if ( per_user is not None ) : _tweets = defaultdict ( list ) for tweet in tweets : if ( len ( _tweets [ tweet . user_name ] ) < per_user ) : _tweets [ tweet . user_name ] . append ( tweet ) tweets = sum ( _tweets . values ( ) , [ ] ) tweets . sort ( key = ( lambda t : t . created_at ) , reverse = True ) if ( ( len ( args ) > 1 ) and str ( args [ ( - 1 ) ] ) . isdigit ( ) ) : tweets = tweets [ : int ( args [ ( - 1 ) ] ) ] return tweets
retrieve tweets for a user .