/* Tweets Resources
162849
@Override
    public void getRetweets(final long statusId) {
        getDispatcher().invokeLater(new AsyncTask(RETWEETS, listeners) {
            @Override
            public void invoke(List<TwitterListener> listeners) throws TwitterException {
                ResponseList<Status> statuses = twitter.getRetweets(statusId);
                for (TwitterListener listener : listeners) {
                    try {
                        listener.gotRetweets(statuses);
                    } catch (Exception e) {
                        logger.warn("Exception at getRetweets", e);
                    }
                }
            }
        });
    }
1291951
protected function addTweetReferences(&$tweet, $data) {
    $typeMap = array(
      'urls' => ReferenceType::URL,
      'user_mentions' => ReferenceType::USER,
      'hashtags' => ReferenceType::HASHTAG,
      'video' => ReferenceType::VIDEO,
      'media' => ReferenceType::MEDIA,
      'photo' => ReferenceType::MEDIA,
      'animated_gif' => ReferenceType::MEDIA,
    );

    foreach ($data['entities'] as $entityType => $entities) {
      foreach ($entities as $entity) {
        $reference = new Reference();
        $reference
            ->setIndices($entity['indices'])
            ->setType($typeMap[$entityType])
            ->setData($entity);

        $tweet->addReference($reference);
      }
    }

    if (isset($data['extended_entities'])) {
      foreach ($data['extended_entities'] as $entities) {
        foreach ($entities as $entity) {
          $reference = new Reference();
          $reference
              ->setIndices($entity['indices'])
              ->setType($typeMap[$entity['type']])
              ->setData($entity);

          $tweet->addReference($reference);
        }
      }
    }
  }
962789
def get_dweets_for(thing_name, key=None, session=None):
    
    if key is not None:
        params = {'key': key}
    else:
        params = None
    return _request('get', '/get/dweets/for/{0}'.format(thing_name), params=params, session=None)
809689
def hydrate(self, iterator):
        
        ids = []
        url = "https://api.twitter.com/1.1/statuses/lookup.json"

        # lookup 100 tweets at a time
        for tweet_id in iterator:
            tweet_id = str(tweet_id)
            tweet_id = tweet_id.strip()  # remove new line if present
            ids.append(tweet_id)
            if len(ids) == 100:
                log.info("hydrating %s ids", len(ids))
                resp = self.post(url, data={
                    "id": ','.join(ids),
                    "include_ext_alt_text": 'true'
                })
                tweets = resp.json()
                tweets.sort(key=lambda t: t['id_str'])
                for tweet in tweets:
                    yield tweet
                ids = []

        # hydrate any remaining ones
        if len(ids) > 0:
            log.info("hydrating %s", ids)
            resp = self.post(url, data={
                "id": ','.join(ids),
                "include_ext_alt_text": 'true'
            })
            for tweet in resp.json():
                yield tweet
6163
def retweet?(status)
      filters = load_filters
      retweet = true
      if !filters.nil?
        filters.each_pair do |path, value|
          array = []
          array << value
          array.flatten.each do |filter_value|
            path_value = StreamBot::ArrayPath.get_path(status, path)
            if path_value.eql?(filter_value) || path_value.include?(filter_value)
              on_match.trigger(status, path, filter_value)
              retweet = false
            end
          end
        end
      end
      retweet
    end
1316904
def tweets_for(query_type, args, per_user=None):
    
    lookup = {"query_type": query_type, "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
213205
public static void main(String[] args) {
        if (args.length < 1) {
            System.out.println("java twitter4j.examples.search.SearchTweets [query]");
            System.exit(-1);
        }
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            Query query = new Query(args[0]);
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
    }
618232
public function getSearchTweets(array $parameters = array(), $multipart = false, $appOnlyAuth = false)
    {
        return $this->get('search/tweets', $parameters, $multipart, $appOnlyAuth);
    }
1085079
function twitterClickHandler(){
    
    var url = $twitter.attr('href') 
    
    $
    .get(url)
    .success(function(data){ 
      
      $spin.hide()
      
      // console.dir(data)
      
      var sorted = []
      var thumbs = ""
      
      if(data.error){
        console.dir(data.error)
        alert(data.error_message)
        return false
      }
      
      $.each(data.media,function(i,el){
        
        thumbs += "<img data-standard-resolution='"
                  + el.full_url
                  +"' src='"+ el.thumb_url+"' />"

      }) // end $.each()
      
      // Add to photoPicker div
      $oneUpTwitterWrapper
        .before(thumbs)

      // Show the photo picker fb section
      $photoPickerTwitter
        .show()

      // Wire up the events to the images...
      wireTwitterGalleryPicker()

      // Progress to Step 2
      progressToNextStep($stepOne, function(){

        $stepTwo.slideDown(333)

      })
      
      // console.dir(sorted)
      
    })
    .error(function(e,b){
      $spin.hide()
      if(e.status === 400) alert(e.responseText || 'Bad request.')
      if(e.status === 401) alert(e.responseText || 'Unauthorized request.')
      if(e.status === 402) alert(e.responseText || 'Forbidden request.')
      if(e.status === 403) alert(e.responseText || 'Forbidden request.')
      if(e.status === 404) alert(e.responseText || 'Images were not found.')
      if(e.status === 405) alert(e.responseText || 'That method is not allowed.')
      if(e.status === 408) alert(e.responseText || 'The request timed out. Try again.')
      if(e.status === 500) alert(e.responseText || 'Something went really wrong.')
    })
    
    return false
    
  }
1263155
def extract_all_snow_tweets_from_disk_generator(json_folder_path):
    
    # Get a generator with all file paths in the folder
    json_file_path_generator = (json_folder_path + "/" + name for name in os.listdir(json_folder_path))

    for path in json_file_path_generator:
        for tweet in extract_snow_tweets_from_file_generator(path):
            yield tweet
725892
protected function createTweetEntities($tweets)
    {
        $entities = [];

        foreach ($tweets as $tweet)
        {
            $user = $this->twitterFactory->createUser($tweet['user']);
            $entities[] = $this->twitterFactory->createTweet($tweet, $user);
        }

        return $entities;
    }
834423
@Override
    public ResponseList<Status> getMentionsTimeline() throws TwitterException {
        return factory.createStatusList(get(conf.getRestBaseURL() + "statuses/mentions_timeline.json"));
    }
535579
def enrich(self, tweet):
        
        tweet = urlize_tweet(expand_tweet_urls(tweet))
        # parses created_at "Wed Aug 27 13:08:45 +0000 2008"

        if settings.USE_TZ:
            tweet['datetime'] = datetime.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y').replace(tzinfo=timezone.utc)
        else:
            tweet['datetime'] = datetime.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y')

        return tweet
1281064
@Override
    public QueryResult search(Query query) throws TwitterException {
        if (query.nextPage() != null) {
            return factory.createQueryResult(get(conf.getRestBaseURL()
                    + "search/tweets.json" + query.nextPage()), query);
        } else {
            return factory.createQueryResult(get(conf.getRestBaseURL()
                    + "search/tweets.json", query.asHttpParameterArray()), query);
        }
    }
659095
public static function linkify($tweet, $target = '_blank')
    {
        if ($target == null) {
            $target = '_blank';
        }

        $tweet = preg_replace_callback(
            "#(^|[\n ])@([a-z0-9_-]*)#is",
            function ($matches) use ($target) {
                return sprintf('%s<a href="https://twitter.com/%s" target="%s" class="user"><span>@</span>%s</a>',
                    $matches[1], $matches[2], $target, $matches[2]);
            }, $tweet
        );

        $tweet = preg_replace_callback(
            "#(^|[\n ])\#([a-z0-9_-]*)#is",
            function ($matches) use ($target) {
                return sprintf('%s<a href="https://twitter.com/search?q=%%23%s" target="%s" class="hashtag"><span>#</span>%s</a>',
                    $matches[1], $matches[2], $target, $matches[2]);
            }, $tweet
        );

        $tweet = preg_replace_callback(
            "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#is",
            function ($matches) use ($target) {
                return sprintf('%s<a href="%s" target="%s" class="link">%s</a>',
                    $matches[1], $matches[2], $target, $matches[2]);
            }, $tweet
        );

        $tweet = preg_replace_callback(
            "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is",
            function ($matches) use ($target) {
                return sprintf('%s<a href="http://%s" target="%s" class="link">%s</a>',
                    $matches[1], $matches[2], $target, $matches[2]);
            }, $tweet
        );

        return $tweet;
    }
884974
private function getTweetsVars($tweets, $vars)
    {
        /** @var string $firstTweetId */
        $firstTweetId = $tweets[0]->getId();

        $vars['previous'] = $this->tweetRepository
            ->getPreviousTweetId($firstTweetId);
        $vars['next'] = $this->tweetRepository
            ->getNextTweetId($firstTweetId);

        // Only update the cookie if the last Tweet Id is bigger than
        //  the one in the cookie
        if ($firstTweetId > $vars['cookieId']) {
            $vars['cookie'] = $this->createCookie($firstTweetId);
            $vars['cookieId'] = $firstTweetId;
        }

        $vars['number'] = $this->tweetRepository
            ->countPendingTweets($vars['cookieId']);

        $vars['first'] = $firstTweetId;

        return $vars;
    }
1189324
public function tweets($limit = 1000)
    { 
        $params = [
            'index' => $this->_esindex,
            'type' => $this->_estype,
            'size' => $limit,
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];
        $query = $this->_es->search($params);
        if ($query['hits']['total'] >= 1)
            $result = $query['hits']['hits'];
        else
            $result = [];
        return $result;
    }