Пример #1
0
    def write_readings(self, spacecraft_name, journey_id, data):
        # Batch Statements are used as a more efficient way to write groups of data to the server

        batch = BatchStatement()
        batch.batch_type = BatchType.UNLOGGED

        for row in data:
            this_pressure_reading = SpacecraftPressure(spacecraft_name,
                                                       journey_id, row)

            batch.add(
                self.insert_prep_stmt.bind({
                    'spacecraft_name':
                    this_pressure_reading.spacecraft_name,
                    'journey_id':
                    this_pressure_reading.journey_id,
                    'pressure':
                    this_pressure_reading.pressure,
                    'pressure_unit':
                    this_pressure_reading.pressure_unit,
                    'reading_time':
                    this_pressure_reading.reading_time
                }))

        self._session.execute(batch)
Пример #2
0
    def write(self, data):
        batch = BatchStatement()
        batch.batch_type = BatchType.UNLOGGED

        for site in data:
            curr_site = NewsSite(site)
            batch.add(
                self.insert.bind({
                    'link': curr_site.link,
                    'title': curr_site.title,
                    'score': curr_site.score,
                    'summary': curr_site.summary
                }))

        self._session.execute(batch)