Exemplo n.º 1
0
    def replies_to_trump_statuses(self, json_data):
        """Logs all replies to Trump's statuses.

        """
        try:
            hashtags = json_data['entities']['hashtags']

            r = Reply.create(
                in_reply_to_status_id_str=json_data[
                    'in_reply_to_status_id_str'],
                user_id=json_data['user']
                ['id_str'],  # do not even need, just here for possible testing
                location=json_data['user']['location'],
                created_at=datetime.datetime.fromtimestamp(
                    float(json_data['timestamp_ms']) / 1000.0),
            )
            self._store_hashtags(r, hashtags)

            return {
                'activity_type':
                'reply',
                'in_reply_to_status_id_str':
                json_data['in_reply_to_status_id_str'],
                'hashtags':
                hashtags if hashtags else None,
                'user_id':
                json_data['user']
                ['id_str'],  # do not even need, just here for possible testing
                'location':
                json_data['user']['location'],
                'created_at':
                datetime.datetime.fromtimestamp(
                    float(json_data['timestamp_ms']) / 1000.0),
            }
        except Exception as e:
            print(e)