예제 #1
0
    def to_classification_object(cls, json):
        c = ClassifiedObject()
        
        c.source = 'twitter'
        c.text = json['text']
        c.created_at = json['created_at']
        c.author = json['user']['screen_name']
        c.location = json['geo']

        return c
예제 #2
0
    def to_classification_object(cls, json):
        c = ClassifiedObject()

        c.source = 'twitter'
        c.text = json['text']
        c.created_at = json['created_at']
        c.author = json['user']['screen_name']
        c.location = json['geo'] or \
            {
                'longitude' : 18 + random.random(),
                'latitude' : 59 + random.random()
            }

        return c
예제 #3
0
    def to_classification_object(cls, json):
        c = ClassifiedObject()
        
        c.source = 'twitter'
        c.text = json['text']
        c.created_at = json['created_at']
        c.author = json['user']['screen_name']
        c.location = json['geo'] or \
            { 
                'longitude' : 18 + random.random(),
                'latitude' : 59 + random.random()
            }

        return c    
예제 #4
0
    def get(self):
        try:
            limit = int(self.get_argument('limit', 10))
        except ValueError:
            raise tornado.web.HTTPError(400)

        query = {}

        # Search for classified objects exceeding thresholds if supplied
        thresholds = self.get_argument('thresholds', None)
        if thresholds:
            thresholds = simplejson.loads(thresholds)
            for tag, threshold in thresholds.iteritems():
                query['tags.' + tag] = { '$gte' : threshold }

        # Limit to a daterange if supplied
        start_time = self.get_argument('start_time', None)
        if start_time:
            start_time = datetime.fromtimestamp(long(start_time))
            query['last_modified'] = {}
            query['last_modified']['$gte'] = start_time

        end_time = self.get_argument('end_time', None)
        if end_time:
            end_time = datetime.fromtimestamp(long(end_time))
            if 'last_modified' not in query:
                query['last_modified'] = {}
            query['last_modified']['$lte'] = end_time

        results = ClassifiedObject.find(
            query=query,
            limit=limit,
            sort=[("last_modified", pymongo.DESCENDING)]
        )

        dicts = [ c.to_dict() for c in results ]
        json = simplejson.dumps(dicts, default=nosy.util.json_serializer)

        self.set_header("Content-Type", "application/json")
        self.write(json)