lookyloo/bin/async_capture.py

40 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pathlib import Path
import logging
2020-10-09 18:05:04 +02:00
from typing import Optional
from lookyloo.abstractmanager import AbstractManager
2019-04-05 16:12:54 +02:00
from lookyloo.helpers import get_homedir, set_running, unset_running, shutdown_requested
2019-01-30 14:30:01 +01:00
from lookyloo.lookyloo import Lookyloo
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
level=logging.INFO, datefmt='%I:%M:%S')
2020-11-05 14:14:33 +01:00
class AsyncCapture(AbstractManager):
2020-10-09 18:05:04 +02:00
def __init__(self, storage_directory: Optional[Path]=None, loglevel: int=logging.INFO):
super().__init__(loglevel)
if not storage_directory:
self.storage_directory = get_homedir() / 'scraped'
self.lookyloo = Lookyloo()
def _to_run_forever(self):
2020-11-05 14:14:33 +01:00
set_running('async_capture')
2019-04-05 16:12:54 +02:00
while True:
2020-11-05 14:14:33 +01:00
url = self.lookyloo.process_capture_queue()
2019-04-05 16:12:54 +02:00
if url is None or shutdown_requested():
break
2020-11-05 14:14:33 +01:00
unset_running('async_capture')
def main():
2020-11-05 14:14:33 +01:00
m = AsyncCapture()
m.run(sleep_in_sec=1)
if __name__ == '__main__':
main()