def test_guess_created(fs): info = FileInfo('foo') assert info.guess_created() is None fs.create_file('foo') assert info.guess_created().isoformat() == '2012-02-03T04:05:06+00:00' info.created = datetime(1, 2, 3, 4, 5, 6) assert info.guess_created() == datetime(1, 2, 3, 4, 5, 6)
def _info(self, info: FileInfo): info.title = self.meta.get('title') info.created = self.meta.get('created') info.tags = {k.lower() for k in self.meta.get('keywords', []) }.union(self._hashtags) info.links = [LinkInfo(self.path, r.href) for r in sorted(self.hrefs)]
def _info(self, info: FileInfo): info.title = self._title() info.created = self._created() info.tags = self._tags() info.links = [ LinkInfo(self.path, href) for href in sorted(self._link_els.keys()) ]
def info(self, path: str, fields: FileInfoReqIsh = FileInfoReq.internal(), path_resolved=False) -> FileInfo: self._refresh_if_needed() if not path_resolved: path = os.path.abspath(path) fields = FileInfoReq.parse(fields) cursor = self.connection.cursor() cursor.execute('SELECT id, title, created FROM files WHERE path = ?', (path, )) file_row = cursor.fetchone() info = FileInfo(path) if file_row: file_id = file_row[0] info.title = file_row[1] time_field = file_row[2] if time_field: if time_field.isnumeric(): info.created = datetime.utcfromtimestamp( int(time_field) / 1000) else: info.created = datetime.fromisoformat(time_field) if fields.tags: cursor.execute('SELECT tag FROM file_tags WHERE file_id = ?', (file_id, )) info.tags = {r[0] for r in cursor} if fields.links: cursor.execute( 'SELECT href FROM file_links WHERE referrer_id = ?', (file_id, )) info.links = [ LinkInfo(path, href) for href in sorted(r[0] for r in cursor) ] if fields.backlinks: cursor.execute( 'SELECT referrers.path, file_links.href' ' FROM files referrers' ' INNER JOIN file_links ON referrers.id = file_links.referrer_id' ' WHERE file_links.referent_id = ?', (file_id, )) info.backlinks = [ LinkInfo(referrer, href) for referrer, href in cursor ] info.backlinks.sort(key=attrgetter('referrer', 'href')) return info
def _info(self, info: FileInfo): info.title = self._meta.get('/Title') info.created = _pdf_strptime(self._meta.get('/CreationDate')) info.tags.update(self._tags())