Only search for tweets entered via given source

        :param source: String. Name of the source to search for. An example \
        would be ``source=twitterfeed`` for tweets submitted via TwitterFeed
        :raises: TwitterSearchException
768519
def set_source_filter(self, source):
        

        if isinstance(source, str if py3k else basestring) and len(source) >= 2:
            self.source_filter = source
        else:
            raise TwitterSearchException(1009)
473438
def read_data(self, **kwargs):
        
        twitter_status_url = 'https://www.twitter.com/{}/status/{}'
        twitter_fav_url = 'https://www.twitter.com/{}/status/{}'
        now = arrow.utcnow().to(settings.TIME_ZONE)
        my_tweets = []
        search = {}
        since_id = None
        trigger_id = kwargs['trigger_id']
        date_triggered = arrow.get(kwargs['date_triggered'])

        def _get_tweets(twitter_obj, search):
            """
                get the tweets from twitter and return the filters to use :
                search and count

                :param twitter_obj: from Twitter model
                :param search: filter used for twython.search() or
                twython.get_user_timeline())
                :type twitter_obj: Object
                :type search: dict
                :return: count that limit the quantity of tweet to retrieve,
                the filter named search, the tweets
                :rtype: list
            
                explanations about statuses :
                when we want to track the tweet of a screen 'statuses' contain all of them
                when we want to track all the tweet matching a tag 'statuses' contain statuses + metadata array
                this is why we need to do statuses = statuses['statuses']
                to be able to handle the result as for screen_name
            """

            # get the tweets for a given tag
            # https://dev.twitter.com/docs/api/1.1/get/search/tweets
            statuses = ''
            count = 100
            if twitter_obj.tag:
                count = 100
                search['count'] = count
                search['q'] = twitter_obj.tag
                search['result_type'] = 'recent'
                # do a search
                statuses = self.twitter_api.search(**search)
                # just return the content of te statuses array
                statuses = statuses['statuses']

            # get the tweets from a given user
            # https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
            elif twitter_obj.screen:
                count = 200
                search['count'] = count
                search['screen_name'] = twitter_obj.screen

                # call the user timeline and get his tweet
                try:
                    if twitter_obj.fav:
                        count = 20
                        search['count'] = 20
                        # get the favorites https://dev.twitter.com/rest/
                        # reference/get/favorites/list
                        statuses = self.twitter_api.get_favorites(**search)
                    else:
                        statuses = self.twitter_api.get_user_timeline(**search)
                except TwythonAuthError as e:
                    logger.error(e.msg, e.error_code)
                    update_result(trigger_id, msg=e.msg, status=False)

            return count, search, statuses

        if self.token is not None:
            kw = {'app_label': 'th_twitter', 'model_name': 'Twitter', 'trigger_id': trigger_id}
            twitter_obj = super(ServiceTwitter, self).read_data(**kw)

            # https://dev.twitter.com/rest/public/timelines
            if twitter_obj.since_id is not None and twitter_obj.since_id > 0:
                since_id = twitter_obj.since_id
                search = {'since_id': twitter_obj.since_id}

            # first request to Twitter
            count, search, statuses = _get_tweets(twitter_obj, search)

            if len(statuses) > 0:
                newest = None
                for status in statuses:
                    if newest is None:
                        newest = True
                        # first query ; get the max id
                        search['max_id'] = max_id = status['id']

                since_id = search['since_id'] = statuses[-1]['id'] - 1

                count, search, statuses = _get_tweets(twitter_obj, search)

                newest = None
                if len(statuses) > 0:
                    my_tweets = []
                    for s in statuses:
                        if newest is None:
                            newest = True
                            max_id = s['id'] - 1
                        screen_name = s['user']['screen_name']
                        # get the text of the tweet + url to this one
                        if twitter_obj.fav:
                            url = twitter_fav_url.format(screen_name, s['id_str'])
                            title = _('Tweet Fav from @{}'.format(screen_name))
                        else:
                            url = twitter_status_url.format(screen_name, s['id_str'])
                            title = _('Tweet from @{}'.format(screen_name))
                        # Wed Aug 29 17:12:58 +0000 2012
                        my_date = arrow.get(s['created_at'], 'ddd MMM DD HH:mm:ss Z YYYY')
                        published = arrow.get(my_date).to(settings.TIME_ZONE)
                        if date_triggered is not None and published is not None and now >= published >= date_triggered:
                            if s.get('extended_entities'):
                                # get a media
                                extended_entities = s['extended_entities']
                                if extended_entities.get('media'):
                                    medias = extended_entities.get('media')
                                    for media in medias:
                                        text = s['text'] + ' ' + media.get('media_url_https')
                            else:
                                text = s['text']

                            my_tweets.append({'title': title,
                                              'content': text,
                                              'link': url,
                                              'my_date': my_date})
                            # digester
                            self.send_digest_event(trigger_id, title, url)
                    cache.set('th_twitter_' + str(trigger_id), my_tweets)
                    Twitter.objects.filter(trigger_id=trigger_id).update(
                        since_id=since_id,
                        max_id=max_id,
                        count=count)
        return my_tweets
289126
def find_this(search, source=SOURCE):
    """"""
    print("Searching for {what}.".format(what=search))
    if not search or not source:
        print("Not found on source: {what}.".format(what=search))
        return ""
    return str(re.compile(r'.*__{what}__ = "(.*?)"'.format(
        what=search), re.S).match(source).group(1)).strip()
312391
def _check_source(cls, source_file_hash, source):
        
        embedding_name = cls.__name__.lower()
        if source not in source_file_hash:
            raise KeyError('Cannot find pre-trained source {} for token embedding {}. '
                           'Valid pre-trained file names for embedding {}: {}'.format(
                               source, embedding_name, embedding_name,
                               ', '.join(source_file_hash.keys())))
843540
public static void main(String[] args) throws TwitterException {
        if (args.length < 1) {
            System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]");
            System.exit(-1);
        }

        TwitterStream twitterStream = new TwitterStreamFactory().getInstance().addListener(new StatusListener() {
            @Override
            public void onStatus(Status status) {
                System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
                System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
            }

            @Override
            public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
                System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
            }

            @Override
            public void onScrubGeo(long userId, long upToStatusId) {
                System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
            }

            @Override
            public void onStallWarning(StallWarning warning) {
                System.out.println("Got stall warning:" + warning);
            }

            @Override
            public void onException(Exception ex) {
                ex.printStackTrace();
            }
        });

        ArrayList<Long> follow = new ArrayList<Long>();
        ArrayList<String> track = new ArrayList<String>();
        for (String arg : args) {
            if (isNumericalArgument(arg)) {
                for (String id : arg.split(",")) {
                    follow.add(Long.parseLong(id));
                }
            } else {
                track.addAll(Arrays.asList(arg.split(",")));
            }
        }
        long[] followArray = new long[follow.size()];
        for (int i = 0; i < follow.size(); i++) {
            followArray[i] = follow.get(i);
        }
        String[] trackArray = track.toArray(new String[track.size()]);

        // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
        twitterStream.filter(new FilterQuery(0, followArray, trackArray));
    }
158859
def search(ont, searchterm):
    
    namedGraph = get_named_graph(ont)
    query = """
    SELECT ?c ?l WHERE {{
    GRAPH <{g}>  {{
    ?c rdfs:label ?l
    FILTER regex(?l,'{s}','i')
    }}
    }}
    """.format(s=searchterm, g=namedGraph)
    bindings = run_sparql(query)
    return [(r['c']['value'],r['l']['value']) for r in bindings]
308825
def _stream_search(self, *args, **kwargs):
        """"""
        for hit in scan(
            self.elastic, query=kwargs.pop("body", None), scroll="10m", **kwargs
        ):
            hit["_source"]["_id"] = hit["_id"]
            yield hit["_source"]
662198
def limitted_dump(cursor=None, twitter=None, path='tweets.json', limit=450, rate=TWITTER_SEARCH_RATE_LIMIT, indent=-1):
    
    if not twitter:
        twitter = get_twitter()
    cursor = cursor or 'python'
    if isinstance(cursor, basestring):
        cursor = get_cursor(twitter, search=cursor)
    newline = '\n' if indent is not None else ''
    if indent < 0:
        indent = None
    # TODO: keep track of T0 for the optimal "reset" sleep duration
    with (open(path, 'w') if not isinstance(path, file) else path) as f:
        f.write('[\n')
        for i, obj in enumerate(cursor):
            f.write(json.dumps(obj, indent=indent))
            if i < limit - 1:
                f.write(',' + newline)
            else:
                break
            remaining = int(twitter.get_lastfunction_header('x-rate-limit-remaining'))
            if remaining > 0:
                sleep(1. / rate)
            else:
                sleep(15 * 60)
        f.write('\n]\n')
97480
def search(self, search_phrase, limit=None):
        
        # SQLite FTS can't find terms with `-`, therefore all hyphens were replaced with underscore
        # before save. Now to get appropriate result we need to replace all hyphens in the search phrase.
        # See http://stackoverflow.com/questions/3865733/how-do-i-escape-the-character-in-sqlite-fts3-queries
        search_phrase = search_phrase.replace('-', '_')
        query, query_params = self._make_query_from_terms(search_phrase)

        self._parsed_query = (query, query_params)

        connection = self.backend.library.database.connection
        # Operate on the raw connection
        connection.connection.create_function('rank', 1, _make_rank_func((1., .1, 0, 0)))

        logger.debug('Searching datasets using `{}` query.'.format(query))
        results = connection.execute(query,
                                     **query_params).fetchall()  # Query on the Sqlite proxy to the raw connection

        datasets = defaultdict(DatasetSearchResult)
        for result in results:
            vid, score = result
            datasets[vid] = DatasetSearchResult()
            datasets[vid].vid = vid
            datasets[vid].b_score = score

        logger.debug('Extending datasets with partitions.')
        for partition in self.backend.partition_index.search(search_phrase):
            datasets[partition.dataset_vid].p_score += partition.score
            datasets[partition.dataset_vid].partitions.add(partition)
        return list(datasets.values())
464560
def usernames(
        self
        ):
        
        try:
            return list(set([tweet.username for tweet in self]))
        except:
            log.error("error -- possibly a problem with tweets stored")
1218246
def next(self):
        """"""
        if self.limit and self.limit == self.num_tweets:
            raise StopIteration

        if self.index >= len(self.results) - 1:
            data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)

            if hasattr(self.method, '__self__'):
                old_parser = self.method.__self__.parser
                # Hack for models which expect ModelParser to be set
                self.method.__self__.parser = ModelParser()

            # This is a special invocation that returns the underlying
            # APIMethod class
            model = ModelParser().parse(self.method(create=True), data)
            if hasattr(self.method, '__self__'):
                self.method.__self__.parser = old_parser
                result = self.method.__self__.parser.parse(self.method(create=True), data)
            else:
                result = model

            if len(self.results) != 0:
                self.index += 1
            self.results.append(result)
            self.model_results.append(model)
        else:
            self.index += 1
            result = self.results[self.index]
            model = self.model_results[self.index]

        if len(result) == 0:
            raise StopIteration
        # TODO: Make this not dependant on the parser making max_id and
        # since_id available
        self.max_id = model.max_id
        self.num_tweets += 1
        return result
1183862
def get_amount_of_tweets(self):
        

        if not self.__response:
            raise TwitterSearchException(1013)

        return (len(self.__response['content']['statuses'])
                if self.__order_is_search
                else len(self.__response['content']))
164032
def search_for(self, query, include_draft=False):
        
        query = query.lower()
        if not query:
            return []

        def contains_query_keyword(post_or_page):
            contains = query in post_or_page.title.lower() \
                       or query in Markup(
                get_parser(post_or_page.format).parse_whole(
                    post_or_page.raw_content)
            ).striptags().lower()
            return contains

        return filter(contains_query_keyword,
                      chain(self.get_posts(include_draft=include_draft),
                            self.get_pages(include_draft=include_draft)
                            if current_app.config[
                                'ALLOW_SEARCH_PAGES'] else []))
672760
def find_source(self, source):
        
        if not is_valid_url(source):
            try:
                source = self.get_source(name=source)
            except SourceNotFound:
                source = self.get_source(url=source)
        else:
            source = self.get_source(url=source)
        return source
521080
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            List<SavedSearch> savedSearches = twitter.getSavedSearches();
            for (SavedSearch savedSearch : savedSearches) {
                System.out.println("[name:" + savedSearch.getName() + " query:" + savedSearch.getQuery() + " id:"
                        + savedSearch.getId() + "]");
            }
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to retrieve saved searches: " + te.getMessage());
            System.exit(-1);
        }
    }
299937
def search(self):
        ''''''
        s = super(TopicSearchMixin, self).search()
        s = s.filter('bool', should=[
            Q('term', tags=tag) for tag in self.topic.tags
        ])
        return s
908787
def search(self, name):
        
        pattern = re.compile(name)
        result = {}
        for i in self.__allstockno:
            query = re.search(pattern, self.__allstockno[i])
            if query:
                query.group()
                result[i] = self.__allstockno[i]
        return result