예제 #1
0
    def get_data(self):
        g = GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=True)

        if (self.start < datetime.datetime.now() - self.TIMEDELTA_DEFAULT_TIMEFRAME) and (self.start + self.TIMEDELTA_DEFAULT_TIMEFRAME > self.end):
            end = self.start + self.TIMEDELTA_DEFAULT_TIMEFRAME
        query_nrt = self.query

        # scrub tweet display query for no retweets
        not_rt = "-(is:retweet)"
        if (not_rt not in query_nrt):
            query_nrt = query_nrt.replace("is:retweet", "")
            query_nrt = "%s %s" % (query_nrt, not_rt)

        print "%s (%s)" % (query_nrt, self.query_count)

        if self.query_count > 500:
            g.paged = True

        tweets = None
        try:
            tweets = g.query_api(query_nrt, self.query_count, use_case="tweets", start=self.start.strftime(self.DATE_FORMAT), end=self.end.strftime(self.DATE_FORMAT))
        except GNIPQueryError as e:
            return handleQueryError(e)

        return tweets
예제 #2
0
    def create(self):
        """
        Returns data in format {"columns": } used in UI
        """
        # New gnip client with fresh endpoint
        g = GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=True)
        columns = []
        for q in self.queries:
            timeline = None
            try:
                timeline = g.query_api(pt_filter = str(q),
                            max_results = 0,
                            use_case = "timeline",
                            start = self.start.strftime(self.DATE_FORMAT),
                            end = self.end.strftime(self.DATE_FORMAT),
                            count_bucket = self.interval,
                            csv_flag = False)
            except GNIPQueryError as e:
                print e

            # Process timeseries on the GNIP Data
            time_series_data = Timeseries(q, timeline, columns, self.total, self.x_axis)
            column = time_series_data.columns

            if self.x_axis == None:
                self.x_axis = time_series_data.xAxis
                columns.insert(0, self.x_axis)

            columns.append(time_series_data.series)
            self.total = time_series_data.total

        return columns
예제 #3
0
    def get_data(self):
        g = GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=True)

        if (self.start < datetime.datetime.now() -
                self.TIMEDELTA_DEFAULT_TIMEFRAME) and (
                    self.start + self.TIMEDELTA_DEFAULT_TIMEFRAME > self.end):
            end = self.start + self.TIMEDELTA_DEFAULT_TIMEFRAME
        query_nrt = self.query

        # scrub tweet display query for no retweets
        not_rt = "-(is:retweet)"
        if (not_rt not in query_nrt):
            query_nrt = query_nrt.replace("is:retweet", "")
            query_nrt = "%s %s" % (query_nrt, not_rt)

        print "%s (%s)" % (query_nrt, self.query_count)

        if self.query_count > 500:
            g.paged = True

        tweets = None
        try:
            tweets = g.query_api(query_nrt,
                                 self.query_count,
                                 use_case="tweets",
                                 start=self.start.strftime(self.DATE_FORMAT),
                                 end=self.end.strftime(self.DATE_FORMAT))
        except GNIPQueryError as e:
            return handleQueryError(e)

        return tweets
예제 #4
0
 def api(self):
     """
     Returns GNIPSearchAPI
     """
     return GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=False)
예제 #5
0
    def get_data(self):
        """
        Returns data for frequency in list view
        """
        # New gnip client with fresh endpoint (this one sets to counts.json)

        g = GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=True)
        timeline = None
        try:
            timeline = g.query_api(self.query, self.sample, use_case="wordcount", start=self.start.strftime(self.DATE_FORMAT), end=self.end.strftime(self.DATE_FORMAT), csv_flag=False)
        except GNIPQueryError as e:
            print(e);

        result = g.freq.get_tokens(20)
        return result
예제 #6
0
def get_gnip(paged=False):
    """
    Returns Gnip Search API
    """
    g = GnipSearchAPI(settings.GNIP_USERNAME,
                      settings.GNIP_PASSWORD,
                      settings.GNIP_SEARCH_ENDPOINT,
                      paged=paged)
    return g
예제 #7
0
    def get_data(self):
        """
        Returns data for frequency in list view
        """
        # New gnip client with fresh endpoint (this one sets to counts.json)

        g = GnipSearchAPI(settings.GNIP_USERNAME,
                          settings.GNIP_PASSWORD,
                          settings.GNIP_SEARCH_ENDPOINT,
                          paged=True)
        timeline = None
        try:
            timeline = g.query_api(self.query,
                                   self.sample,
                                   use_case="wordcount",
                                   start=self.start.strftime(self.DATE_FORMAT),
                                   end=self.end.strftime(self.DATE_FORMAT),
                                   csv_flag=False)
        except GNIPQueryError as e:
            print(e)

        result = g.freq.get_tokens(20)
        return result