Beispiel #1
0
 def update_database(self):
     filenames = get_scanned_filenames(self.directory)
     latest = self.get_latest()
     for filename in filenames:
         dt = datetime_from_pdf_filename(filename)
         if latest is None or dt > latest.created:
             q = self.session.query(ScannedDocument)
             q = q.filter_by(name=filename)
             try:
                 q.one()
             except NoResultFound:
                 self.insert_scanned_file(filename)
Beispiel #2
0
 def insert_scanned_file(self, filename):
     fullname = os.path.join(self.directory, filename)
     # file must fit in memory
     content = file(fullname).read()
     created = datetime_from_pdf_filename(filename)
     with transaction.manager:
         f = File()
         f.content = content
         self.session.add(f)
         f = self.session.merge(f)
         s = ScannedDocument()
         s.created = created
         s.name = filename
         s.file_id = f.id
         self.session.add(s)
         s = self.session.merge(s)
     return s