Exemplo n.º 1
0
    def parse(self, data, clock):
        if not data:  # nothing received or nothing in the history -> nothing to parse
            return None
        data = JOb(data)
        result = JOb()
        result.text = data.text
        result.user_id = data.user.id
        result.timestamp = datetime.datetime.fromtimestamp(int(data.timestamp_ms)/1000).strftime('%Y-%m-%d %H:%M:%S') #data.timestamp_ms
        result.tweet_id = data.id
        if 'place' in data and data.place is not None:
            result.bounding_box = "[" + ";".join([",".join(map(str, a)) for a in data.place.bounding_box.coordinates[0]]) + "]"
        else:
            result.bounding_box = "[]"
            # print "no bounding box!"

        result.lat = ""
        result.long = ""
        if 'coordinates' in data and data.coordinates is not None and data.coordinates.type == "Point":
            result.long = str(data.coordinates.coordinates[0])
            result.lat  = str(data.coordinates.coordinates[1])

        # insert into DB
        if hasattr(self, 'cur'):
            self.cur.execute(self.insert_stmt, result.raw())
            self.db.commit()

        result.geotag = self.geometry_to_wkt(data.geo) if data.geo else ""
        # print result
        del data
        return super(TwitterParser, self).parse(result, clock)