mirror of https://github.com/CIRCL/lookyloo
chg: Slight cleanups and improvments
parent
6149df06eb
commit
72463cc898
|
@ -7,6 +7,8 @@ import json
|
|||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from .exceptions import LookylooException
|
||||
|
||||
|
||||
@dataclass
|
||||
class CaptureCache():
|
||||
|
@ -23,8 +25,10 @@ class CaptureCache():
|
|||
self.capture_dir: Path = cache_entry['capture_dir']
|
||||
elif not cache_entry.get('error'):
|
||||
missing = set(self.__default_cache_keys) - set(cache_entry.keys())
|
||||
raise Exception(f'Missing keys ({missing}), no error message. It should not happen.')
|
||||
raise LookylooException(f'Missing keys ({missing}), no error message. It should not happen.')
|
||||
|
||||
# Error without all the keys in __default_cache_keys was fatal.
|
||||
# if the keys in __default_cache_keys are present, it was an HTTP error
|
||||
self.error: Optional[str] = cache_entry.get('error')
|
||||
self.incomplete_redirects: bool = True if cache_entry.get('incomplete_redirects') == 1 else False
|
||||
self.no_index: bool = True if cache_entry.get('no_index') == 1 else False
|
||||
|
|
|
@ -453,12 +453,12 @@ class Lookyloo():
|
|||
(capture_dir / 'no_index').touch()
|
||||
|
||||
@property
|
||||
def capture_uuids(self):
|
||||
def capture_uuids(self) -> List[str]:
|
||||
'''All the capture UUIDs present in the cache.'''
|
||||
return self.redis.hkeys('lookup_dirs')
|
||||
return self.redis.hkeys('lookup_dirs') # type: ignore
|
||||
|
||||
@property
|
||||
def sorted_cache(self):
|
||||
def sorted_cache(self) -> List[CaptureCache]:
|
||||
'''Get all the captures in the cache, sorted by timestamp (new -> old).'''
|
||||
all_cache: List[CaptureCache] = []
|
||||
p = self.redis.pipeline()
|
||||
|
@ -490,7 +490,7 @@ class Lookyloo():
|
|||
return None
|
||||
try:
|
||||
return CaptureCache(cached)
|
||||
except Exception as e:
|
||||
except LookylooException as e:
|
||||
self.logger.warning(f'Cache ({capture_dir}) is invalid ({e}): {json.dumps(cached, indent=2)}')
|
||||
return None
|
||||
|
||||
|
|
Loading…
Reference in New Issue