def read_new(self, db, reader_name): """Update the readings and raw statements in the database.""" from indra_reading.readers import get_reader_class self.end_datetime = self.run_datetime latest_updatetime = self._get_latest_updatetime(db, reader_name) if latest_updatetime is not None: self.begin_datetime = latest_updatetime - self.buffer else: raise ReadingUpdateError("There are no previous updates for %s. " "Please run_all." % reader_name) constraints = self._get_constraints(db, reader_name) tcid_q = db.filter_query( db.TextContent.id, db.TextContent.insert_date > self.begin_datetime, *constraints ) if self.only_unread: reader_class = get_reader_class(reader_name) reader_version = reader_class.get_version() tcid_q = tcid_q.except_( db.filter_query(db.Reading.text_content_id, db.Reading.reader == reader_name, db.Reading.reader_version == reader_version) ) tcids = {tcid for tcid, in tcid_q.all()} if not tcids: logger.info("Nothing new to read with %s." % reader_name) return False self._run_reading(db, tcids, reader_name) return True
def from_db_reading(cls, db_reading): """Construct a DatabaseReadingData object from an entry in the database As returned by SQL Alchemy. """ if db_reading.bytes: if db_reading.format == formats.JSON: reading = json.loads(unpack(db_reading.bytes)) else: reading = unpack(db_reading.bytes) else: reading = None return cls(db_reading.text_content_id, get_reader_class(db_reading.reader), db_reading.reader_version, db_reading.format, reading, db_reading.id)
def get_version(self, reader_name): from indra_reading.readers import get_reader_class return get_reader_class(reader_name).get_version()
def get_version(self, reader_name): return get_reader_class(reader_name).get_version()