def _get(self, service):
        tweets = []
        services = [service] if service else tweeter.SERVICES
        for service in services:
            tweets += self.tweet_manager.get(service)

        return encoding.to_json({"messages": [encoding.to_dict(m) for m in tweets]})
Esempio n. 2
0
 def _get(self, service):
     tweets = []
     services = [service] if service else tweeter.SERVICES
     for service in services:
         tweets += self.tweet_manager.get(service)
     return encoding.to_json(
         {'messages': [encoding.to_dict(m) for m in tweets]})
    def _get(self):
        messages = {}  # messages by date + service

        for service in tweeter.SERVICES:
            tweet = self.tweet_manager.get_last_message(service)
            if tweet:
                if tweet.created_at < datetime.utcnow() - timedelta(days=1):
                    tweet = None
            messages[service] = encoding.to_dict(tweet) if tweet else None

        return encoding.to_json({"messages": messages})
Esempio n. 4
0
    def _get(self):
        messages = {}  # messages by date + service

        for service in tweeter.SERVICES:
            tweet = self.tweet_manager.get_last_message(service)
            if tweet:
                if tweet.created_at < datetime.utcnow() - timedelta(days=1):
                    tweet = None
            messages[service] = encoding.to_dict(tweet, ) if tweet else None

        return encoding.to_json({
            'messages': messages,
        })
    def _get(self):
        offset = int(self.request.get("offset", 0))
        max_date = datetime.utcnow() - timedelta(days=offset)
        min_date = max_date - timedelta(days=30)
        messages = defaultdict(list)  # messages by service
        messages["min"] = time.mktime(min_date.timetuple())
        messages["max"] = time.mktime(max_date.timetuple())

        for service in tweeter.SERVICES:
            tweets = self.tweet_manager.get_by_dates(service, max_date=max_date, min_date=min_date)
            tweets = [t for t in tweets]
            messages[service] = [encoding.to_dict(m) for m in reversed(tweets)]

        return encoding.to_json({"messages": messages})
Esempio n. 6
0
    def _get(self):
        offset = int(self.request.get('offset', 0))
        max_date = datetime.utcnow() - timedelta(days=offset)
        min_date = max_date - timedelta(days=30)
        messages = defaultdict(list)  # messages by service
        messages['min'] = time.mktime(min_date.timetuple())
        messages['max'] = time.mktime(max_date.timetuple())

        for service in tweeter.SERVICES:
            tweets = self.tweet_manager.get_by_dates(
                service,
                max_date=max_date,
                min_date=min_date,
            )
            tweets = [t for t in tweets]
            messages[service] = [encoding.to_dict(m) for m in reversed(tweets)]

        return encoding.to_json({
            'messages': messages,
        })