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 pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
|
from .exceptions import LookylooException
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CaptureCache():
|
class CaptureCache():
|
||||||
|
@ -23,8 +25,10 @@ class CaptureCache():
|
||||||
self.capture_dir: Path = cache_entry['capture_dir']
|
self.capture_dir: Path = cache_entry['capture_dir']
|
||||||
elif not cache_entry.get('error'):
|
elif not cache_entry.get('error'):
|
||||||
missing = set(self.__default_cache_keys) - set(cache_entry.keys())
|
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.error: Optional[str] = cache_entry.get('error')
|
||||||
self.incomplete_redirects: bool = True if cache_entry.get('incomplete_redirects') == 1 else False
|
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
|
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()
|
(capture_dir / 'no_index').touch()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def capture_uuids(self):
|
def capture_uuids(self) -> List[str]:
|
||||||
'''All the capture UUIDs present in the cache.'''
|
'''All the capture UUIDs present in the cache.'''
|
||||||
return self.redis.hkeys('lookup_dirs')
|
return self.redis.hkeys('lookup_dirs') # type: ignore
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sorted_cache(self):
|
def sorted_cache(self) -> List[CaptureCache]:
|
||||||
'''Get all the captures in the cache, sorted by timestamp (new -> old).'''
|
'''Get all the captures in the cache, sorted by timestamp (new -> old).'''
|
||||||
all_cache: List[CaptureCache] = []
|
all_cache: List[CaptureCache] = []
|
||||||
p = self.redis.pipeline()
|
p = self.redis.pipeline()
|
||||||
|
@ -490,7 +490,7 @@ class Lookyloo():
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return CaptureCache(cached)
|
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)}')
|
self.logger.warning(f'Cache ({capture_dir}) is invalid ({e}): {json.dumps(cached, indent=2)}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue